开发者

Customize the UINavigationBar backButton

I am always setting the backgroundImages of UINavigationBars, but I never worked ou开发者_JAVA百科t how to set the backgroundImage of a the back button of a UINavigationBar.

How could I do this?


UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0,0,36,30);
[button setBackgroundImage:[UIImage imageNamed:@"backgroundImage.png"] forState:UIControlStateNormal];

//[button setTitle:@"  Back" forState:UIControlStateNormal];
//[button.titleLabel setFont:[UIFont boldSystemFontOfSize:11]];

[button addTarget:self.navigationController action:@selector(popViewControllerAnimated:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
[self.navigationItem setLeftBarButtonItem:barButtonItem];


I think you will have to create a custom button for the backBarButtonItem, and then customize it.

If you are looking for tutorials, then go to this question - How do you change color/image on the default backBarButtonItem? and I think you find your answer there.

For making a bar button item look like a backBarButtonItem, refer to this answer. Creating a left-arrow button (like UINavigationBar's "back" style) on a UIToolbar


UIButton *backbutton = [UIButton buttonWithType:UIButtonTypeCustom];
backbutton.frame = CGRectMake(0,0,36,30);
[backbutton setBackgroundImage:[UIImage imageNamed:@"backgroundImage.png"] forState:UIControlStateNormal];

[backbutton addTarget:self.navigationController action:@selector(popViewControllerAnimated:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backbutton];
[self.navigationItem setLeftBarButtonItem:barButtonItem];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜