2

I want to add this Image on my Navigation Bar button, How can I use this image on my navigation Right Bar button or Left bar button?

enter image description here

Please check below code those I am using to View same like work code on Navigation bar button:-

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

Let me know How to use this code on navigation bar button.

Thank You!

Pawan Rai
  • 3,434
  • 4
  • 32
  • 42
Shriram Kadam
  • 394
  • 1
  • 4
  • 20
  • Possible duplicate of [How do I change the title of the "back" button on a Navigation Bar](http://stackoverflow.com/questions/1449339/how-do-i-change-the-title-of-the-back-button-on-a-navigation-bar) – Shriram Kadam Sep 16 '16 at 09:44

1 Answers1

1

I have tried your code, with a little trick of mine and it work like magic.

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

You need to give a image to barButton at first, so your button can make its frame

Screenshot of my test

Pawan Rai
  • 3,434
  • 4
  • 32
  • 42