我正在尝试将导航栏的标题与我的应用程序的中心对齐,但标题似乎停留在右侧(请找到屏幕截图)。我正在使用下面的代码:
-(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;
当我隐藏后退按钮时,标题显示居中对齐的标题。有什么方法可以设置后退按钮的外观属性吗?
谁能指导我哪里可能出错了。