简体   繁体   English

UITableView背景图片问题

[英]UITableView background image problem

I am using UITableView.I set the tableview background image like this. 我正在使用UITableView.I像这样设置tableview背景图像。

self.tableView.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"bg.png"]];

在此输入图像描述

I am using table style as grouped. 我正在使用表格样式进行分组。 But in display I am getting black shadow on left and right side of grouped cell. 但在显示中,我在分组单元格的左侧和右侧出现黑色阴影。

How to remove this black shadow? 如何删除这个黑影?

Thanks in Advance. 提前致谢。

Try this.. 试试这个..

self.tableView.backgroundColor=[UIColor clearColor];
UIImage *backgroundImage = [UIImage imageNamed:@"sample2.png"];
UIImageView *backgroundImageView = [[UIImageView alloc]initWithImage:backgroundImage]; 
self.tableView.backgroundView=backgroundImageView;
[backgroundImageView release];

First, set the background image for the table's parent view to the image that you want: 首先,将表的父视图的背景图像设置为所需的图像:

[parentView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"bg.png"]];

Then, set the background image for the UITableView to clearColor: 然后,将UITableView的背景图像设置为clearColor:

self.tableView.backgroundColor = [UIColor clearColor];

That should solve the problem. 那应该可以解决问题。

You can use these lines instead of the above line to get rid of black color : 您可以使用这些行代替上面的行来消除黑色:

UIImage *backgroundImage = [UIImage imageNamed:@"b.jpg"];   
UIImageView *backgroundView = [[UIImageView alloc]initWithImage:backgroundImage];
[self.view addSubview:backgroundView];  
[self.view sendSubviewToBack:backgroundView];   

将opaque属性设置为NO

[self.tableView setOpaque: NO];

Set the tableview's backgroundColor to clearColor and set the tableview's backgroundView to nil and it will show the color of the view on which it was added on to. 将tableview的backgroundColor设置为clearColor,并将tableview的backgroundView设置为nil,它将显示添加它的视图的颜色。 And if your tableview is a standalone grouped style table view controller, then set its opaque property to NO. 如果您的tableview是一个独立的分组样式表视图控制器,则将其opaque属性设置为NO。

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

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