2010-10-06 97 views

回答

4

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

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