2013-08-29 20 views
1

我在我的按鈕中有一個gif,但它顯示爲只是藍色框。在ios中添加圖像到我的按鈕是藍色

(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的。是什麼賦予了?

+0

嘗試使用'UIImageView'顯示GIF。 –

+1

iOS不支持GIF圖像 – Tendulkar

+0

@chris您必須對您的問題答案給出回覆,這不是獲取幫助的方法。 atlist你給予答覆,誰給你回答你的問題的用戶。謝謝 –

回答

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: -

Discussions

Display animated GIF in iOS

1

嘗試設置[按鈕將backgroundImage],它將圖像的任何格式設置爲您