如图所示,我已成功通过代码自定义UINavigationController的navigationBar的背景:
UINavigationController *nav = ......
[[nav navigationBar] setBackgroundImage:[UIImage imageNamed:@"bg_daohang"] forBarMetrics:UIBarMetricsDefault];
现在,我想在navigationBar上自定义项目(在红色圆圈中)。是否可以这样做以及如何做到这一点?
答案 0 :(得分:1)
UIButton *button =[UIButton buttonWithType:UIButtonTypeCustom];
button.frame=CGRectMake(0.0, 0, 60.0, 30.0);
[button setBackgroundImage:[UIImage imageNamed:@"logout.png"] forState:UIControlStateNormal];
[button setTitle:@"Logout" forState:UIControlStateNormal];
button.titleLabel.font = [UIFont boldSystemFontOfSize:13];
[button addTarget:self action:@selector(logout) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:button];
self.navigationItem.rightBarButtonItem= item;
[item release];