我正在制作一个带有 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/