【发布时间】:2011-01-04 01:46:47
【问题描述】:
我正在添加一个UILabel 实例作为我的自定义UITableViewCell 实例的contentView 的子视图。
当我选择单元格时,该行以蓝色突出显示,标签的背景除外。标签文字清晰。
当我将标签和内容视图backgroundColor 属性设置为[UIColor clearColor] 时,标签文本变得模糊。
如何将标签背景颜色设置为清晰,以允许行突出显示,同时仍保持标签文本清晰?
我在别处看到的一个建议是 round 标签的 frame 值,但这没有任何效果。
代码
这是我自定义的UITableViewCell 子视图的-setNeedsLayout 方法的sn-p:
UILabel *_objectTitleLabel = [[UILabel alloc] initWithFrame:CGRectNull];
_objectTitleLabel.text = [self.awsObject cleanedKey];
_objectTitleLabel.font = [UIAppDelegate defaultObjectLabelFont];
_objectTitleLabel.highlightedTextColor = [UIColor clearColor]; //[UIAppDelegate defaultLabelShadowTint];
_objectTitleLabel.backgroundColor = [UIColor clearColor]; //[UIAppDelegate defaultWidgetBackgroundTint];
_objectTitleLabel.frame = CGRectMake(
kCellImageViewWidth + 2.0 * self.indentationWidth,
0.5 * (self.tableView.rowHeight - 1.5 * kCellLabelHeight) + kCellTitleYPositionNudge,
contentViewWidth,
kCellLabelHeight
);
_objectTitleLabel.frame = CGRectIntegral(_objectTitleLabel.frame);
_objectTitleLabel.tag = kObjectTableViewCellTitleSubviewType;
//NSLog(@"_objectTitleLabel: %@", NSStringFromCGRect(_objectTitleLabel.frame));
[self.contentView addSubview:_objectTitleLabel];
[_objectTitleLabel release], _objectTitleLabel = nil;
...
self.contentView.backgroundColor = [UIAppDelegate defaultWidgetBackgroundTint];
self.contentView.clearsContextBeforeDrawing = YES;
self.contentView.autoresizesSubviews = YES;
self.contentView.clipsToBounds = YES;
self.contentView.contentMode = UIViewContentModeRedraw;
【问题讨论】:
-
你能发布你的源代码吗?
-
请查看添加的代码sn-p。
标签: iphone uiview uitableview colors uilabel