我使用以下代码将自定义标题和左键按钮添加到导航栏: -
UIBarButtonItem *button1 =[[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"img1.png"] style:UIBarButtonItemStylePlain target:self action:@selector(popBack)];
UIBarButtonItem *button2 =[[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"img2.png"] style:UIBarButtonItemStylePlain target:self action:nil];
self.navigationItem.leftBarButtonItems = [[NSArray alloc] initWith:button1, button2, nil];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 360, 30)];
[label setFont:[UIFont fontWithName:@"Arial-BoldMT" size:14]];
[label setBackgroundColor:[UIColor clearColor]];
[label setTextColor:[UIColor whiteColor]];
[label setText:@"Detail Controller"];
label.textAlignment = UITextAlignmentCenter; //NSTextAlignmentCenter
self.navigationItem.titleView=label;
此处,左侧栏按钮未正确放置且标题对齐未正确(左侧栏按钮正在将标题推到导航栏的右侧)。