UITableView中textLabel和detailTextLabel的使用

在使用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 :UITableViewCellStyleValue1 reuseIdentifier : @"cell" autorelease ];  

[cell.textLabel setText:@"选项"];

[cell.detailTextLabel setTextColor:[UIColor colorWithWhite:0.52 alpha:1.0]];

[cell.detailTextLabel setText:@"详细内容"];

你可能感兴趣的:(IOS)