2011-02-10 181 views
4

我已经创建了一个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 

回答

-1

我使用自定义标签,用于这一目的。您也可以使用此代码更改字体大小。

例子:

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

希望这有助于。

+0

是的,我也创建了我自定义的UILabel,因为我试图用我的文本解释“我在整个应用程序中使用NavigationBar标题的自定义UILabel”。 我的问题是,我不能从类别访问标题实际设置UILabel导航条的标题。 – oehman 2011-02-10 09:11:23