如何中心我的文字标签导航栏的中心
答
在UIViewController的viewDidLoad方法中使用下面的代码片段。
UILabel *label = [[UILabel alloc] init];
label.text = @"Center Label";
label.frame = CGRectMake(0, 0, 100, 30);
label.textAlignment = NSTextAlignmentCenter;
UIBarButtonItem *customButton = [[UIBarButtonItem alloc] initWithCustomView:label];
self.navigationItem.titleView = customButton.customView;
代码不言自明。根据需要定制标签和其他必要的东西。