如何在自定义表格单元格类别中绘制矩形?该单元格目前有一个带有几个文本标签的背景图片。我想在每个标签后面绘制一个矩形,以便它们更容易阅读详细的背景图像。在自定义表格单元格中绘制矩形
我知道我可以只设置标签的背景颜色,但我希望在背景颜色和文本之间有填充。如果这是可能的,我很想知道如何! :)
我继承在Three20一个TTTableMessageItemCell,方法如下被调用,可以在其中与细胞的子视图玩,
- (void)layoutSubviews {
[super layoutSubviews];
CGFloat padding = 16;
CGFloat boxWidth = self.contentView.width - 2*padding;
CGFloat textWidth = boxWidth - (padding*2);
CGFloat textHeight = 100;
CGFloat top = kTableCellSmallMargin;
// Position Heading Text
_titleLabel.frame = CGRectMake(padding, top, textWidth, _titleLabel.font.ttLineHeight);
top += _titleLabel.height;
// Position Detail Text
[self.detailTextLabel sizeToFit];
self.detailTextLabel.top = top+2*padding;
self.detailTextLabel.left = 2*padding;
self.detailTextLabel.width = textWidth;
self.detailTextLabel.height = 100;
}
我想的矩形被放置在_titleLable背后detailTextLabel标签。
编辑 我已经能够添加使用以下的右边框,
UIView *view = [[UIView alloc] init]; view.backgroundColor = [UIColor whiteColor]; view.frame = CGRectMake(padding, top, textWidth, textHeight+2*padding); [self insertSubview:view belowSubview:self.detailTextLabel];
它铺在标签的顶部,我似乎无法得到它的后面。 ..
编辑 我添加视图到了错误的子视图,以固定它,
[[self.subviews objectAtIndex:0] insertSubview:view atIndex:0];
参见:http://stackoverflow.com/questions/1106658/custom-draw-a-uitableviewcell – magma