I created an AddressBook application in which I show a list of people in a UITableView, when a person is selected, ABPnknownPersonViewController is clicked. From this ABUnknownPersonViewController the user can (using the built-in functions) either add the person to the "New Contact" or "Existing Contact".
That is where my problem is. I am using a custom UILabel for the NavigationBar header throughout the application. And I need to be able to do this for views that are clicked "Add new contact" / "Add to existing contact."
I decided this for "Add a new contact" by creating a category for ABNewPersonViewController, but the same approach does not work for "Add to an existing contact." I assume this may be due to the fact that he clicked the ABPersonPickerNavigationController button.
@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]; }
Color changing for the TintColor NavigationBar works fine, but I can't find the right way to access the title. The help, which includes a working example where you can change the title in ABPeoplePickerNavigationController, which is popped from ABUnknownPersonViewController, will be tested a lot.
Here's what the category for ABNewPersonViewController (which 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
source share