为 backBarButtonItem 制作自定义标题视图
我正在使用 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";
I am making a custom backBarButtonItem
with a PNG and that works just fine. The only question is how to change the text color. The way I did that on my navigation bar was this:
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";
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不要使用 autorelease 将标签设置为 titleview,分配它们后释放它们
dont use autorelease for set label to titleview,after assign them release them