![](/img/trans.png)
[英]Customizing ABPeoplePickerNavigationController's navigationbar in iOS 8
[英]Customizing Title in the NavigationBar for a ABPeoplePickerNavigationController
我创建了一个AddressBook类型的应用程序,当我选择一个人时,我会在UITableView中显示人的列表,并按下ABUnknownPersonViewController。 通过此ABUnknownPersonViewController,用户可以(通过使用内置功能)将人员添加到“新联系人”或“现有联系人”中。
这是我的问题所在。 我在整个应用程序中都将CustomUILabel用于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
我为此使用自定义标签。 您也可以使用此代码更改字体大小。
例:
UILabel * label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 320 / 11)];
label.font = 16.0;
label.textColor = [UIColor blackColor];
label.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.5];
label.backgroundColor = [UIColor clearColor];
label.textAlignment = UITextAlignmentCenter;
label.text = @"Your title";
self.navigationItem.titleView = label;
[label release];
希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.