在ios中将图像添加到我的按钮是蓝色的

时间:2013-08-29 07:18:55

标签: ios objective-c ios6 uibutton

我的按钮中有一个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。是什么给了什么?

3 个答案:

答案 0 :(得分:3)

不支持iOS GIF图像,因此如果您希望设置Image With Animation,请执行以下代码: -

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的Bellow链接: -

Discussions

Display animated GIF in iOS

答案 1 :(得分:1)

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

答案 2 :(得分:0)

SDWebImage声称拥有动画gif支持!

检查出来:

https://github.com/rs/SDWebImage