如何更改表格视图的背景,快速对话框

时间:2012-05-02 19:00:18

标签: iphone

我正在关注一个快速对话框的教程,以创建如下表单 enter image description here

现在,我想更改此表单的背景。有谁知道如何实现这一点,请就此向我提出建议。 感谢

5 个答案:

答案 0 :(得分:1)

如果要将图像显示为背景,请尝试此操作:

tableView.backgroundColor = [UIColor colorWithPattern:@"your_image_here"];

tableView.backgroundColor = [UIColor colorWithRed:128 green:128 blue:128 alpha:1.0];

如果这不起作用,您可以设置表视图的backgroundView属性:

tableView.backgroundView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"your_image_here"]]] autorelease];

答案 1 :(得分:0)

使用backgroundView的{​​{1}}属性。

如果您想使用图片,只需创建一个UITableView并为其设置UIImageView

backgroundView

您也可以使用UIImage *myImage = [UIImage imageNamed:@"foo.png"]; self.tableView.backgroundView = [[UIImageView alloc] initWithImage:myImage]; 调整图片在视图中的适合方式。

contentMode

答案 2 :(得分:0)

您可以尝试UITableView继承或声明的一些属性:

@property(nonatomic, readwrite, retain) UIView *backgroundView @property(nonatomic, copy) UIColor *backgroundColor

第一个可能是你想要的。它由UITableView声明。第二个是继承自UIView

答案 3 :(得分:0)

尝试设置表格视图的背景颜色;它可能需要您将表视图样式从分组更改为普通。

答案 4 :(得分:0)

如果您要设置背景颜色,请尝试此操作...

tableView.backgroundView = nil;
tableView.backgroundColor = [UIColor redColor]; //replace with your colour

但是如果你想要一个模式图像,请不要使用那个方法......这样做..

tableView.backgroundColor = [UIColor clearColor];

UIView *v = [[UIView alloc] init]; //needs memory Managment (arc example)
v.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"pattern.png"]];
tableView.backgroundView = v;

这是因为如果UITableView是组样式的,你有一个带图案的背景图像作为tableviews backgroundColor,那么它也应用于单元格的边缘,但是因为它们是单独的视图,所以模式变得不正确。

希望它有所帮助。