1

I have a gif in my button, but it displays as just blue box.

 (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
    {
    //[self setTitle:@"Register" forState:UIControlStateNormal];
    [self setBackgroundColor:[UIColor whiteColor]];
    [self setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];



    [self setImage:[UIImage imageNamed:@"Person.gif"] forState:UIControlStateNormal];//setting image on button.
}
return self;

}

The image was added correctly to xcode. What gives?

cdub
  • 24,555
  • 57
  • 174
  • 303

3 Answers3

3

iOS GIF image not supported so if you wish to do set Image With Animation do like bellow code:-

UIImageView* animatedImageView = [[UIImageView alloc] initWithFrame:self.view.bounds];
animatedImageView.animationImages = [NSArray arrayWithObjects:    
                               [UIImage imageNamed:@"image1.png"],
                               [UIImage imageNamed:@"image2.png"],
                               [UIImage imageNamed:@"image3.png"],
                               [UIImage imageNamed:@"image4.png"], nil];
animatedImageView.animationDuration = 1.0f;
animatedImageView.animationRepeatCount = 0;
[animatedImageView startAnimating];
[yourButton addSubview: animatedImageView];

For more Check this Bellow link about iOS suported GIF:-

Discussions

Display animated GIF in iOS

Community
  • 1
  • 1
Nitin Gohel
  • 49,482
  • 17
  • 105
  • 144
1

Try to set [button backgroundimage] and it will set any format of image to you

NHS
  • 409
  • 2
  • 7
0

SDWebImage claims to have Animated gif support!

Check it out:

https://github.com/rs/SDWebImage

Guntis Treulands
  • 4,764
  • 2
  • 50
  • 72