您的位置:首页 > 产品设计 > UI/UE

UITableView中textLabel和detailTextLabel的使用

2014-09-03 14:46 267 查看
以前在使用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:@"详细内容"];

同时UITableViewCell中还有imageView等可以直接使用, 需要进一步研究使用.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: