UITableView: textLabel,detailTextLabel

来源:互联网 发布:防伪底纹设计软件 编辑:程序博客网 时间:2024/05/05 12:23
以前在使用UITableView的时候, 总是在cell上自己加label, 遇到cell的accessoryType不同的时候, 需要自己调整label的大小和位置.  后来发现UITableViewCell中有textLabel和detailTextLabel可以使用, 系统配置好了大小位置, 可以根据cell的不同type和大小自动调整.  

textLabel就是放置在cell左边的Label,   detailTextLabel就是放置在cell右边的Label,  使用的时候需要把cell的style设为UITableViewCellStyleValue1.


代码如下:


UITableViewCell *cell = [[[UITableViewCell allocinitWithStyle:UITableViewCellStyleValue1reuseIdentifier:@"cell"autorelease];  

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

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

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



同时UITableViewCell中还有imageView等可以直接使用, 需要进一步研究使用.


0 0