当我创建自己的元素时,UITableViewCell
我使用它layoutSubviews
来排列单元格中的元素。但是,如何创建一个适合所需行数的区域 - 取决于描述文本的长度。
-(void) layoutSubviews {
[super layoutSubviews];
[imageView setFrame:CGRectMake(8.0, 10.0, 20.0, 20.0)];
[description setFrame:CGRectMake(40.0, 1.0, 250.0, 40.0)]; //1..n lines <- ???????
}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
imageView = [[UIImageView alloc] initWithFrame: CGRectZero];
imageView.contentMode = UIViewContentModeScaleAspectFit;
[self.contentView addSubview: imageView];
titleLabel = [[UILabel alloc] initWithFrame: CGRectZero];
[titleLabel setFont:[UIFont systemFontOfSize:14.0]];
[titleLabel setTextColor:[UIColor blackColor]];
[titleLabel setHighlightedTextColor:[UIColor darkGrayColor]];
[titleLabel setLineBreakMode: NSLineBreakByWordWrapping];
//titleLabel.numberOfLines = 2;
[self.contentView addSubview: titleLabel];
description = [[UILabel alloc] initWithFrame: CGRectZero];
[description setFont:[UIFont systemFontOfSize:12.0]];
[description setTextColor:[UIColor darkGrayColor]];
[description setHighlightedTextColor:[UIColor darkGrayColor]];
[description setLineBreakMode: NSLineBreakByWordWrapping];
//description.numberOfLines = 1; //1..n lines <- ???????
[self.contentView addSubview: description];
}