Nauman.Khattak
Nauman.Khattak

Reputation: 641

how should I draw Custom button on Navigation Bar

I want to draw custom button on Navigation bar.

Can anybody help me.

Upvotes: 2

Views: 5362

Answers (3)

Himanshu Mahajan
Himanshu Mahajan

Reputation: 4799

      UIBarButtonItem *btn=[[UIBarButtonItem alloc] initWithTitle:@"Button" style:UIBarButtonItemStylePlain target:self action:@selector(btnPressed)];
      [self.navigationItem setRightBarButtonItem:btn];

Upvotes: 0

Krzysztof Zabłocki
Krzysztof Zabłocki

Reputation: 1307

simple

[[UIBarButtonItem alloc] initWithCustomView: customButton];

will work

so something like that:

UIButton *button = [UIButton buttonWithType: UIButtonTypeCustom];
[button setImage:[UIImage imageNamed:@"animage.png"]];
[button addTarget:self action:@selector(onClick:) forControlEvents: UIControlEventTouchUpInside];
UIBarButtonItem *customItem = [[UIBarButtonItem alloc] initWithCustomView: button];
[self.navigationItem setLeftBarButtonItem:customItem];

Cheers, Krzysztof Zabłocki

Upvotes: 5

Thomas Clayson
Thomas Clayson

Reputation: 29925

UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithTitle:@"DontWorryAboutThis" style:UIBarButtonItemStylePlain target:self action:@selector(method:)];
[barButton setImage:[UIImage imageNamed:@"animage.png"]];
[self.navigationItem setLeftBarButtonItem:barButton];

Upvotes: 3

Related Questions