为ABPeoplePickerNavigationController自定义NavigationBar中的标题 [英] Customizing Title in the NavigationBar for a ABPeoplePickerNavigationController

查看:58
本文介绍了为ABPeoplePickerNavigationController自定义NavigationBar中的标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个地址簿类型的应用程序,其中我在一个UITableView显示的人的列表,当选择一个人的ABUnknownPersonViewController推.通过此ABUnknownPersonViewController,用户可以(通过使用内置功能)将人员添加到新联系人"或现有联系人"中.

I have created an AddressBook kind of application where I display a list of people in a UITableView, when a person is selected an ABUnknownPersonViewController is pushed. From this ABUnknownPersonViewController the user is able (by using the built in functionality) to either add the person to a "New Contact" or "Existing Contact".

这是我的问题所在.我在整个应用程序中为NavigationBar标题使用了自定义UILabel.我还需要能够对添加新联系人"/添加到现有联系人"所推送的视图执行此操作.

This is where my problem is located. I am using a Custom UILabel for the NavigationBar title throughout my application. And I need to be able to do this for the views that are pushed by "Add New Contact" / "Add to Existing Contact" as well.

我通过为ABNewPersonViewController创建一个类别为添加新联系人"解决了此问题,但是对于添加到现有联系人"而言,相同的方法不起作用.我猜这可能是因为它被推送了一个ABPersonPickerNavigationController所致.

I solved this for the "Add New Contact" by creating a category for ABNewPersonViewController, but the same approach doesn't work for the "Add to Existing Contact". I guess this might be due to the fact that is it an ABPersonPickerNavigationController that is pushed.

@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中的标题.

The change of color for the NavigationBar's tintColor works fine, but I cant find a proper way to access the title. Help that include a working example where you are able to change the title in a ABPeoplePickerNavigationController that is pushed from a ABUnknownPersonViewController would be much appriciated.

这是ABNewPersonViewController的类别(起作用的)的样子:

This is how the category for ABNewPersonViewController (that works) looks like:

@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

推荐答案

我为此使用了自定义标签.您还可以使用此代码更改字体大小.

I use custom labels for this purpose. You can also change font size with this code.

示例:

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

希望这会有所帮助.

这篇关于为ABPeoplePickerNavigationController自定义NavigationBar中的标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆