1

我的按钮中有一个 gif,但它只显示为蓝色框。

 (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;

}

图像已正确添加到 xcode。是什么赋予了?

4

3 回答 3

3

不支持 iOS GIF 图像,因此如果您希望设置带有动画的图像,请执行以下代码:-

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];

有关更多信息,请查看有关 iOS 支持的 GIF 的波纹管链接:-

讨论

在 iOS 中显示动画 GIF

于 2013-08-29T07:20:59.217 回答
1

尝试设置 [button backgroundimage] 它将为您设置任何格式的图像

于 2013-08-29T07:30:14.450 回答
0

SDWebImage 声称有动画 gif 支持!

看看这个:

https://github.com/rs/SDWebImage

于 2013-08-29T07:36:28.620 回答