如何中心我的文字标签导航栏的中心

问题描述:

如何找到导航栏的长度....如何中心我的文字标签导航栏的中心

我想显示编程导航栏的标签中心..

使我可以写公式,所以它应该工作,如果我旋转我的设备...

在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; 

代码不言自明。根据需要定制标签和其他必要的东西。