自定义 ABPeoplePickerNavigationController 导航栏中的标题

发布于 2024-10-16 18:20:24 字数 1690 浏览 8 评论 0原文

我创建了一种 AddressBook 类型的应用程序,在 UITableView 中显示人员列表,当选择一个人时,将推送 ABUnknownPersonViewController。从此 ABUnknownPersonViewController 用户能够(通过使用内置功能)将该人添加到“新联系人”或“现有联系人”。

这就是我的问题所在。我在整个应用程序中使用自定义 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];
}

导航栏的色调颜色的颜色变化效果很好,但我找不到访问标题的正确方法。如果包含一个工作示例,您可以更改从 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

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".

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.

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

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.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

硪扪都還晓 2024-10-23 18:20:24

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

示例:

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

希望这会有所帮助。

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

Example:

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

Hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文