天天看点

tableviewcell添加label、button

1.给tableviewcell添加label,首先

然后可以定义label的一些属性

label.backgroundColor = [UIColor grayColor]; //设置背景色

label.text = @"Hello World"; //设置内容

label.textColor = [UIColor blueColor]; //文本颜色

label.backgroundColor = [UIColor clearColor]; //设置label的背景色透明

在这我添加的前三行颜色不一样

若把[cell.contentView addSubview:label];改为[self.view addSubview:label]则label将建立在tableview中,而不是tableviewcell中

2.给tableviewcell添加button

常用的button的属性

button.frame = CGRectMake(150,30,50,20);//button的位置

[button setTitle:@"点击" forState:UIControlStateNormal];

button.backgroundColor = [UIColor blackColor];

3在cell创建image

还有一种办法

用这个办法该图片显示在cell最左侧imageview中

继续阅读