2015-08-29 80 views
2

我想在導航欄按鈕上添加此圖像,如何在導航右欄按鈕或左欄按鈕上使用此圖像?如何在目標c中使用動畫導航欄按鈕

enter image description here

請檢查下面的我使用的瀏覽上的導航欄按鈕同樣喜歡工作代碼代碼: -

- (void)viewDidLoad 
    { 
    [super viewDidLoad]; 
    // Animation 

    UIImageView*animationView = [[UIImageView alloc] initWithFrame:self.view.frame]; 
    animationView.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"],nil]; 
    animationView.animationDuration = 1.25; 
    animationView.animationRepeatCount = 0; 
    [animationView startAnimating]; 
    [self.view addSubview:animationView]; 
} 

讓我知道如何 使用此代碼對導航欄按鈕。

謝謝!

+0

的可能的複製[如何更改的「背」稱號按鈕導航欄上](http://stackoverflow.com/questions/1449339/how-do-i-change-the-title-of-the-back-button-on-a-navigation-bar) –

回答

1

我試過你的代碼,用我的一個小訣竅,它像魔術一樣工作。

NSArray *imageArray = [NSArray arrayWithObjects: 
         [UIImage imageNamed:@"tmp-0"], 
         [UIImage imageNamed:@"tmp-1"], 
         [UIImage imageNamed:@"tmp-2"], 
         [UIImage imageNamed:@"tmp-3"], 
         [UIImage imageNamed:@"tmp-4"], 
         [UIImage imageNamed:@"tmp-5"], 
         [UIImage imageNamed:@"tmp-6"], 
         [UIImage imageNamed:@"tmp-7"],nil]; 

UIButton *barButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
[barButton setImage:[UIImage imageNamed:@"tmp-0"] forState:UIControlStateNormal]; // mine trick 
[barButton.imageView setAnimationImages:imageArray]; 
[barButton.imageView setAnimationDuration:1.0f]; 

[barButton.imageView startAnimating]; 
[barButton sizeToFit]; 

self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:barButton]; 

您需要首先給barButton一個形象,讓您的按鈕可以使它的框架

Screenshot of my test

+0

謝謝!它爲我工作很好。 –

+0

Hello Pawan, 如何在Image視圖上使用此代碼?在視圖 –

+0

@ShriramKadam我不明白,你能解釋一下你的問題嗎? – Pawan