简体   繁体   English

我如何在没有界面生成器的情况下更改tableView的背景?

[英]how do I change the background of tableView without interface builder?

我正在尝试学习如何在不使用Interface Builder的情况下进行编程,并且偶然发现了一个问题,如何将背景从默认的UITableViewStyleGrouped更改为我自己的背景,然后同样适用于单元格,怎么做我无需使用界面生成器即可更改它们。

You could use an image pattern: 您可以使用图像模式:

myTableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"image.png"]];

Or use the UITableView backgroundView attribute: 或使用UITableView backgroundView属性:

self.tableView.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"background.png"]];

尝试设置UITableViewUITableViewCellbackgroundColorbackgroundView

To change the background of the table styled as UITableViewStyleGrouped just use: 要更改样式为UITableViewStyleGrouped的表的背景,只需使用:

myTableView.backgroundColor = [UIColor redColor];

and if you want to change the color of a cell, you can do the following on cellForRowAtIndexPath method: 如果要更改单元格的颜色,可以对cellForRowAtIndexPath方法执行以下操作:

cell.contentView.backgroundColor = [UIColor blueColor];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM