设置 UITableView 中 cell 的背景颜色。
示例1:通过 backgroundView 设置。
1 UIView *view1 = [[UIView alloc] init]; 2 view1.backgroundColor = [UIColor blueColor]; 3 cell.backgroundView = view1;
示例2:通过 backgroundColor 设置。
1 cell.backgroundColor = [UIColor blueColor];
backgroundView 的优先级比 backgroundColor 高,如果同时设置了, backgroundView 会覆盖 backgroundColor 。
设置 cell 选中状态的背景。
1 UIView *view2 = [[UIView alloc] init]; 2 view2.backgroundColor = [UIColor redColor]; 3 cell.selectedBackgroundView = view2;
设置 UITableView 的其他属性。
1 self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; //设置分割线样式 2 self.tableView.separatorColor = [UIColor redColor]; //设置分割线颜色 3 self.tableView.tableHeaderView = [UIButton buttonWithType:UIButtonTypeContactAdd]; //设置顶部视图 4 self.tableView.tableFooterView = [[UISwitch alloc] init]; //设置底部视图
原文:http://www.cnblogs.com/wjq-Law/p/5221020.html