2010-10-06 51 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; 

代碼不言自明。根據需要定製標籤和其他必要的東西。