tags:

views:

567

answers:

1

Hello all,

I want to add customized arrow buttons to UINavigation Bar which comes at the top.

what I want to do is create a custom image button and place it over the bar. When I tried adding to view like:

[self.view addSubview:leftArrowButton];//(Where leftArrowButton is a UIButton with an image of arrow)

This dont work, like it places the button but button gets hided under the bar and not overlap on it.

Any help is appreciated. Thanks.

+1  A: 

Try doing the following:

UINavigationBar *bar = self.navigationController.navigationBar;
bar.titleView = leftArrowButton;  // change title view
bar.leftBarButtonItem = leftArrowButton; // if ref is UIBarButtonItem

You should consider using a UIBarButtonItem rather than UIButton.

You can also customize the bar buttons as well with images (using the initWithImage:style:target:action:):

UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithImage:myImage
                             style:UIBarButtonItemStyleBordered
                            target:self action:@selector(buttonPressed:)];
bar.leftBarButtonItem = item;
[item release];

You can also use any view you like (with some consideration for the size) using the initWithCustomView::

UIBarButtonItem *item = [[UIBarButtonItem alloc]
                           initWithCustomView:leftArrowButton];
bar.leftBarButtonItem = item;
[item release];
notnoop
I know I can use barButtonItem but then I cant customize the button. I want to customize the button.
rkb
Updated post to describe how to customize `UIBarButtonItem`.
notnoop