2013-05-31 100 views
0

由於PIC節目,我已經成功定製由代碼中的UINavigationController的的導航欄的背景:自上的導航欄的導航項目

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

enter image description here

現在,我想自定義的導航欄上的項目(在紅色圓圈中)。是否有可能做到這一點,以及如何做到這一點?

回答

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];