小编use*_*938的帖子

设置导航栏标题的对齐方式

我正在尝试将导航栏的标题与我的应用程序中心对齐,但似乎标题是留在右侧(请找到屏幕截图).我正在使用以下代码:

-(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];
}
Run Code Online (Sandbox Code Playgroud)

viewWillAppear()下面

[self.navigationItem setTitle:offertitle];
Run Code Online (Sandbox Code Playgroud)

并试过这个

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;
Run Code Online (Sandbox Code Playgroud)

当我隐藏后退按钮时,标题显示中心对齐的标题.是否有任何方法可以设置后退按钮的外观属性?

图像链接在这里

任何人都可以指导我可能出错的地方.

iphone cocoa-touch objective-c ios

3
推荐指数
1
解决办法
1万
查看次数

标签 统计

cocoa-touch ×1

ios ×1

iphone ×1

objective-c ×1