在使用UITableView的时候, 总是在cell上自己加label, 遇到cell的accessoryType不同的时候, 需要自己调整label的大小和位置. 后来发现UITableViewCell中有textLabel和detailTextLabel可以使用, 系统配置好了大小位置, 可以根据cell的不同type和大小自动调整.
textLabel就是放置在cell左边的Label, detailTextLabel就是放置在cell右边的Label, 使用的时候需要把cell的style设为UITableViewCellStyleValue1.
代码如下:
UITableViewCell *cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1reuseIdentifier:@"cell"] autorelease];
[cell.textLabel setText:@"选项"];
[cell.detailTextLabel setTextColor:[UIColor colorWithWhite:0.52 alpha:1.0]];
[cell.detailTextLabel setText:@"详细内容"];
本文介绍如何在UITableView的UITableViewCell中利用textLabel和detailTextLabel来简化布局工作。通过设置cell样式为UITableViewCellStyleValue1,可以自动调整label的位置与大小,适应不同类型的cell。
7970

被折叠的 条评论
为什么被折叠?



