Display GIF Image
Some Times we require to display Gif images in ios so if we display using UIImageView then it will display as a constant image ,no movement in the image.
I have used in UIalertController to make attractive .
1: Save the Image as .gif extension in any places in computer directory.
2: Go to That Url “http://ezgif.com/split” and upload Gif image . so it will Split image into the number of Frames and download it.
3: Make a folder and store all images in that folder and drag to your project directory.
Note: images save in folder in like 1.gif,2.gif… so please named as regular number so that you can easily store in NSArray .
4: write that code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
+(void)alertController:(UIWindow *)alertnew msg:(NSString *)textMessage{ UIWindow *currentWindow = alertnew; UIImageView* animatedImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,50,50)]; animatedImageView.animationImages = [NSArray arrayWithObjects: [UIImage imageNamed:@"1.gif"], [UIImage imageNamed:@"2.gif"], [UIImage imageNamed:@"3.gif"], [UIImage imageNamed:@"4.gif"], [UIImage imageNamed:@"5.gif"], [UIImage imageNamed:@"6.gif"],[UIImage imageNamed:@"7.gif"], [UIImage imageNamed:@"8.gif"], [UIImage imageNamed:@"9.gif"], [UIImage imageNamed:@"10.gif"], [UIImage imageNamed:@"11.gif"], [UIImage imageNamed:@"12.gif"],[UIImage imageNamed:@"13.gif"],[UIImage imageNamed:@"13.gif"],[UIImage imageNamed:@"14.gif"],[UIImage imageNamed:@"15.gif"],[UIImage imageNamed:@"16.gif"],[UIImage imageNamed:@"17.gif"],[UIImage imageNamed:@"18.gif"],[UIImage imageNamed:@"19.gif"],[UIImage imageNamed:@"20.gif"],[UIImage imageNamed:@"21.gif"],[UIImage imageNamed:@"22.gif"],[UIImage imageNamed:@"23.gif"],[UIImage imageNamed:@"24.gif"],[UIImage imageNamed:@"25.gif"],[UIImage imageNamed:@"26.gif"],[UIImage imageNamed:@"27.gif"],[UIImage imageNamed:@"28.gif"],[UIImage imageNamed:@"29.gif"],[UIImage imageNamed:@"30.gif"],[UIImage imageNamed:@"31.gif"],[UIImage imageNamed:@"32.gif"],[UIImage imageNamed:@"33.gif"],[UIImage imageNamed:@"34.gif"],[UIImage imageNamed:@"35.gif"],[UIImage imageNamed:@"36.gif"],[UIImage imageNamed:@"37.gif"],[UIImage imageNamed:@"38.gif"],[UIImage imageNamed:@"39.gif"],[UIImage imageNamed:@"40.gif"],[UIImage imageNamed:@"41.gif"],[UIImage imageNamed:@"42.gif"],[UIImage imageNamed:@"43.gif"],[UIImage imageNamed:@"44.gif"],[UIImage imageNamed:@"45.gif"],[UIImage imageNamed:@"46.gif"],[UIImage imageNamed:@"47.gif"],[UIImage imageNamed:@"48.gif"],[UIImage imageNamed:@"49.gif"],[UIImage imageNamed:@"50.gif"],[UIImage imageNamed:@"51.gif"],[UIImage imageNamed:@"52.gif"],[UIImage imageNamed:@"53.gif"],[UIImage imageNamed:@"54.gif"],[UIImage imageNamed:@"55.gif"],[UIImage imageNamed:@"56.gif"],[UIImage imageNamed:@"57.gif"],[UIImage imageNamed:@"58.gif"],[UIImage imageNamed:@"59.gif"],[UIImage imageNamed:@"60.gif"],[UIImage imageNamed:@"61.gif"],[UIImage imageNamed:@"62.gif"],[UIImage imageNamed:@"63.gif"],[UIImage imageNamed:@"64.gif"],[UIImage imageNamed:@"65.gif"],[UIImage imageNamed:@"66.gif"],[UIImage imageNamed:@"67.gif"],[UIImage imageNamed:@"68.gif"],[UIImage imageNamed:@"69.gif"],[UIImage imageNamed:@"70.gif"],[UIImage imageNamed:@"71.gif"],[UIImage imageNamed:@"72.gif"],[UIImage imageNamed:@"73.gif"],[UIImage imageNamed:@"74.gif"],[UIImage imageNamed:@"75.gif"],[UIImage imageNamed:@"76.gif"],[UIImage imageNamed:@"77.gif"], nil]; animatedImageView.animationDuration = 3.0f; animatedImageView.animationRepeatCount = 0; [animatedImageView startAnimating]; UIView *alertView = [[UIView alloc] initWithFrame:CGRectMake(0,0, 256, 96)]; alertView.layer.borderColor = [GlobalData colorWithHexString : @"000000"].CGColor; alertView.layer.borderWidth = 1.0f; alertView.tag = 121212; alertView.backgroundColor = [UIColor whiteColor]; alertView.layer.cornerRadius = 10; UILabel *sortTitle = [[UILabel alloc] initWithFrame:CGRectMake(0, 10, 256, 20)]; [sortTitle setTextColor : [GlobalData colorWithHexString : @"000000"]]; [sortTitle setBackgroundColor : [UIColor clearColor]]; [sortTitle setFont : [UIFont fontWithName : @"Trebuchet MS" size : 18.0f]]; [sortTitle setText :textMessage]; sortTitle.adjustsFontSizeToFitWidth = YES; sortTitle.textAlignment = NSTextAlignmentCenter; [alertView addSubview : sortTitle]; UIView *sampleView = [[UIView alloc] initWithFrame:CGRectMake(0,35, 256, 50)]; sampleView.backgroundColor = [UIColor whiteColor]; [sampleView addSubview:animatedImageView]; [alertView addSubview:sampleView]; animatedImageView.center = CGPointMake(sampleView.frame.size.width / 2, sampleView.frame.size.height / 2); alertView.center = currentWindow.center; [currentWindow addSubview:alertView]; } |
5 : Here (1.gif,2.gif are split images of actual gif image.)
6: Now write that static method in the Global class and call like this.
UIWindow * currentWindow = [UIApplication sharedApplication].keyWindow;
[GlobalData alertController:currentWindow msg:@”Please Wait….”];
here GlobalData is global class .
Remove Or dismiss
[[currentWindow viewWithTag:121212] removeFromSuperview];
7: Happy coding………………