iPhone - 上的UITableViewController设置背景 [英] iPhone - Setting background on UITableViewController

查看:233
本文介绍了iPhone - 上的UITableViewController设置背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么办法来设置一个的UITableViewController?

后台视图

我试着用我使用一个的UIViewController ,但鉴于code过来的表视图中的所有内容。如果我在添加背景视图的cellForRowAtIndexPath法,它没有显示在所有。有没有人这样做过,或有它是如何做的想法?
这里是code我使用的:

 的UIImage *图像= [UIImage的imageNamed:@background.jpg];
* UIImageView的背景图像= [[UIImageView的页头] initWithImage:图片];
[self.view addSubview:背景图像]。
[self.view sendSubviewToBack:背景图像]。


解决方案

(这基本上是与上述相同汉斯·埃斯彭的解决方案,但使用便利的方法为简便起见)

将这个 - [UITableViewControllerSubclass的viewDidLoad] 方法:

  self.tableView.backgroundColor = [的UIColor colorWithPatternImage:[UIImage的imageNamed:@BackgroundPattern.png]];

有在避免在viewDidLoad方法一对夫妇的自动释放的没有意义的,因为它仅仅被很少调用(当观点实际上负载),并因此对性能的影响甚微。

N.B。你应该总是在iPhone上,而不是JPEG或任何其他形式使用PNG图像。

Is there any way to set a background view on a UITableViewController?

I try with the code I am using on a UIViewController, but the view comes over all the contents of the table view. If I add the background view in the cellForRowAtIndexPath-method, it is not showing at all. Has anyone done this before or have an idea on how it can be done? Here is the code I am using:

UIImage *image = [UIImage imageNamed: @"background.jpg"];
UIImageView *backImage = [[UIImageView alloc] initWithImage: image];
[self.view addSubview: backImage];
[self.view sendSubviewToBack: backImage];

解决方案

(This is basically the same as Hans Espen's solution above, but uses convenience methods for brevity)

Put this in your -[UITableViewControllerSubclass viewDidLoad] method:

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

There's no point in avoiding a couple of autoreleases in a viewDidLoad method, since it only gets called rarely (when the view actually loads) and will therefore have negligible impact on performance.

N.B. You should always use PNG images on the iPhone, not JPEG or any other format.

这篇关于iPhone - 上的UITableViewController设置背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆