views:

49

answers:

2

Hi all.

I want to draw custom button on Navigation bar.

Can anybody help me.

+1  A: 

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

Krzysztof Zabłocki
and how can i add image to this custom button :)
Nauman.Khattak
and where to add this custom button means in which method... In ViewDidLoad() method.....
Nauman.Khattak
you could add it in viewDidLoad
Krzysztof Zabłocki
but it has hide my back button which was there....
Nauman.Khattak
sure, because you change left button ( left button is usually back button ), change right one [self.navigationItem setRightBarButtonItem:customItem];
Krzysztof Zabłocki
A: 
UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithTitle:@"DontWorryAboutThis" style:UIBarButtonItemStylePlain target:self action:@selector(method:)];
[barButton setImage:[UIImage imageNamed:@"animage.png"]];
[self.navigationItem setLeftBarButtonItem:barButton];
Thomas Clayson
i impletment this code but it hide my back button.
Nauman.Khattak
If you want back button, then you should not set leftBarButtonItem. If you want leftBarButtonItem, then you have no back button.
Toro
then use rightBarButtonItem
Thomas Clayson