于titleview框会自动调整,如果你想获得这样的结果,你可以试试这个:
UILabel *titleLabel = [[UILabel alloc] initWithFrame:self.navigationController.navigationBar.frame];
[titleLabel setTextAlignment:UITextAlignmentRight];
[titleLabel setText:@"Your title"];
[titleLabel setBackgroundColor:[UIColor clearColor]];
[titleLabel setTextColor:[UIColor whiteColor]];
self.navigationItem.titleView = titleLabel;
注意:一定不要设置你的视图控制器self.title否则你会覆盖titleView
另一种解决方案可以把titleLabel放入一个UIBarButtonItem(customView)并设置它喜欢self.navigationItem.rightBarButtonItem这样你就不需要设置文字对齐了,标签的框架可以是正确的文字大小
然后添加为子视图。 – Desdenova 2013-04-30 09:50:45