我已經創建了一個AddressBook類型的應用程序,我在UITableView中顯示人員列表,當選擇一個人時推送了一個ABUnknownPersonViewController。通過ABUnknownPersonViewController,用戶可以(通過使用內置功能)將該人添加到「新聯繫人」或「現有聯繫人」中。在NavigationBar中爲ABPeoplePickerNavigationController自定義標題
這是我的問題所在。我在整個應用程序中使用NavigationBar標題的自定義UILabel。而且我需要能夠爲「添加新聯繫人」/「添加到現有聯繫人」所推送的視圖執行此操作。
我通過爲ABNewPersonViewController創建類別解決了「添加新聯繫人」的問題,但同樣的方法對於「添加到現有聯繫人」不起作用。我想這可能是由於這是推送的ABPersonPickerNavigationController。
@implementation ABPeoplePickerNavigationController (customTitle)
-(void)viewDidLoad {
[super viewDidLoad];
self.navigationBar.tintColor = [UIColor colorWithRed:102/255.0 green:102/255.0 blue:102/255.0 alpha:1];
}
NavigationBar的tintColor的顏色變化工作正常,但我無法找到正確的方式來訪問標題。包含一個可以更改從ABUnknownPersonViewController推送的ABPeoplePickerNavigationController中的標題的工作示例的幫助將非常有用。
這是ABNewPersonViewController(的作品)類別的樣子:
@implementation ABNewPersonViewController (customTitle)
-(void)viewDidLoad {
[super viewDidLoad];
self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:102/255.0 green:102/255.0 blue:102/255.0 alpha:1];
}
-(void)setTitle:(NSString *)theTitle {
CGRect frame = CGRectMake(0, 0, 45, 45);
UILabel *label = [[[UILabel alloc] initWithFrame:frame] autorelease];
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont systemFontOfSize:20.0];
label.shadowColor = [UIColor colorWithWhite:255.0 alpha:1];
label.shadowOffset = CGSizeMake(1, 1);
label.textAlignment = UITextAlignmentCenter;
label.textColor = [UIColor colorWithRed:23/255.0 green:23/255.0 blue:23/255.0 alpha:1];
self.navigationItem.titleView = label;
label.text = theTitle;
[label sizeToFit];
}
@end
是的,我也創建了我自定義的UILabel,因爲我試圖用我的文本解釋「我在整個應用程序中使用NavigationBar標題的自定義UILabel」。 我的問題是,我不能從類別訪問標題實際設置UILabel導航條的標題。 – oehman 2011-02-10 09:11:23