gpt4 book ai didi

objective-c - 为 backBarButtonItem 创建自定义标题 View

转载 作者:行者123 更新时间:2023-11-29 13:47:47 26 4
gpt4 key购买 nike

我正在制作一个带有 PNG 的自定义 backBarButtonItem,效果很好。唯一的问题是如何更改文本颜色。我在导航栏上的做法是这样的:

CGRect frame = CGRectMake(0, 0, 400, 44);
UILabel *label = [[[UILabel alloc] initWithFrame:frame] autorelease];
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont boldSystemFontOfSize:20.0];
label.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.5];
label.textAlignment = UITextAlignmentCenter;
label.textColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"aColor.png"]];
self.navigationItem.titleView = label;
label.text = @"aTitle";

最佳答案

不要使用 autorelease 将标签设置为 titleview,分配后释放它们

        CGRect frame = CGRectMake(0, 0, 400, 44);

UILabel *label = [[UILabel alloc] initWithFrame:frame];

label.backgroundColor = [UIColor clearColor];

label.font = [UIFont boldSystemFontOfSize:20.0];

label.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.5];

label.textAlignment = UITextAlignmentCenter;

label.textColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"aColor.png"]];

label.text = @"aTitle";

self.navigationItem.titleView = label;

[label release];

关于objective-c - 为 backBarButtonItem 创建自定义标题 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6552073/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com