0

如图所示,我已经通过代码成功自定义了 UINavigationController 的 navigationBar 的背景:

UINavigationController *nav = ......
[[nav navigationBar] setBackgroundImage:[UIImage imageNamed:@"bg_daohang"] forBarMetrics:UIBarMetricsDefault];

在此处输入图像描述

现在,我想自定义导航栏上的项目(在红色圆圈中)。是否有可能做到这一点以及如何做到这一点?

4

1 回答 1

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];
于 2013-05-31T02:36:47.590 回答