title爲圖片時:
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 100, 40)];
imageView.image = [UIImage imageNamed:@"daohangtitle"];
self.navigationItem.titleView = imageView;
title爲文字時:
UILabel *tittle=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 44)];
[tittle setBackgroundColor:[UIColor clearColor]];
[tittle setTextColor:[UIColor whiteColor]];
tittle.text=@"首頁";
[tittle setTextAlignment:NSTextAlignmentCenter];
[tittle setFont:[UIFont systemFontOfSize:24]];
self.navigationItem.titleView=tittle;
自定義左右按鈕
UIButton *btnLeft = [UIButton buttonWithType:UIButtonTypeCustom];
[btnLeft setFrame:CGRectMake(0, 0, 33, 31)];
[btnLeft setBackgroundImage:[UIImage imageNamed:@"btn_go"] forState:UIControlStateNormal];
[btnLeft setBackgroundImage:[UIImage imageNamed:@"btn_go_hig"] forState:UIControlStateSelected];
[btnLeft addTarget:self action:@selector(didMore) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btnLeft];
// self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btnLeft];