[英]Place a background Image behind a grouped UITableView
I've a grouped UITableView which has been resized and rounded. 我有一个已经调整大小和舍入的分组UITableView。 I would like to place a view BEHIND this table.I've tried:
我想在这张桌子旁边放一个视图。我试过:
[self.tableView addSubview:backgroundView];
[self.tableView sendSubviewToBack:backgroundView];
but it didn't work. 但它不起作用。 This is what I obtain:
这是我获得的:
I would like to have the background in place of the black space. 我想用背景代替黑色空间。
Any idea? 任何想法?
How about [self.tableView setBackgroundView:backgroundView];
怎么样
[self.tableView setBackgroundView:backgroundView];
? ?
Bear with me I'm a beginner. 忍受我,我是初学者。 I just ran into this problem and I found two solutions.
我刚遇到这个问题,我找到了两个解决方案。 In my case, I was using a UITableView object.
在我的例子中,我使用的是UITableView对象。
To begin, add the background image into your app's directory. 首先,将背景图像添加到应用程序的目录中。 I put mine in "Supporting Files"
我把它放在“支持文件”中
You can add the image as a UIColor object: 您可以将图像添加为UIColor对象:
...
[resultsTable setBackGroundColor:setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"background.jpg"]]];
...
The problem with this method is that it will repeat your background image because it's treating it as a pattern. 这种方法的问题在于它会重复你的背景图像,因为它将它视为一种模式。
The better way: 更好的方法:
// Create a string to store the path location of your image, otherwise you would have to provide an exact path name
NSString *backPath = [[NSBundle mainBundle] pathForResource:@"background"
ofType:@"jpg"];
// Create a UIImage Object to store the image.
UIImage *bgImage = [[UIImage alloc ] initWithContentsOfFile:backPath];
// Create a UIImageView which the TableView
UIImageView *bgView = [[UIImageView alloc]initWithImage:bgImage];
// Set your TableView's background property, it takes a UIView Obj.
[resultsTable setBackgroundView: bgView];
.....
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.