我正在尝试将应用程序导航栏标题居中对齐,但似乎标题仍停留在右侧(请查看截图)。 我正在使用以下代码:
-(void)viewDidLoad {
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithTitle:@"Home" style:UIBarButtonItemStylePlain target:self action:@selector(goToHomePage:)];
[self.navigationController.navigationItem.rightBarButtonItem setTarget:self];
self.navigationItem.rightBarButtonItem = addButton;
[addButton release];
}
在下面的
viewWillAppear()
方法中:[self.navigationItem setTitle:offertitle];
我尝试了这个
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(40, 0, 120, 40)];
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont boldSystemFontOfSize:14.0];
label.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.5];
label.textAlignment = UITextAlignmentLeft;
label.textColor =[UIColor whiteColor];
label.text=offertit;
self.navigationItem.titleView = label;
当我隐藏返回按钮时,标题显示居中对齐的标题。有没有办法设置返回按钮的外观属性? 图片链接在这里 请问有人可以指导我哪里错了吗?