我有一个自定义的UINavigationBar标题和一个自定义的返回按钮。我的问题是标题在iPhone上没有居中显示,好像我的返回按钮将标题推向了右侧。你有什么想法如何让它居中显示吗?
int height = self.navigationController.navigationBar.frame.size.height;
int width = self.navigationController.navigationBar.frame.size.width;
UILabel *navLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, width + 300, 20)];
navLabel.backgroundColor = [UIColor whiteColor];
navLabel.textColor = [UIColor redColor];
navLabel.font = [UIFont fontWithName:@"Helvetica" size:30];
navLabel.textAlignment = UITextAlignmentCenter;
self.navigationItem.titleView = navLabel;
[navLabel release];
((UILabel *)self.navigationItem.titleView).text = self.title;
谢谢!
编辑 我删除了多余的代码并添加了这张图片:
请注意,标题被推到一边以适应按钮....