【发布时间】:2011-06-24 16:52:32
【问题描述】:
我已经创建了一个地址簿类型的应用程序,我在 UITableView 中显示人员列表,当一个人被选中时,一个 ABUnknownPersonViewController 被推送。通过这个 ABUnknownPersonViewController,用户可以(通过使用内置功能)将该人添加到“新联系人”或“现有联系人”。
这是我的问题所在。我在整个应用程序中使用自定义 UILabel 作为 NavigationBar 标题。我还需要能够为“添加新联系人”/“添加到现有联系人”推送的视图执行此操作。
我通过为 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
【问题讨论】:
标签: iphone objective-c uinavigationbar uilabel abaddressbook