iPhone - 在 UITableViewController 上设置背景

标签 iphone background uitableview

有什么方法可以在 UITableViewController 上设置背景 View 吗?

我尝试使用在 UIViewController 上使用的代码,但 View 覆盖​​了 TableView 的所有内容。如果我在 cellForRowAtIndexPath-method 中添加背景 View ,它根本不会显示。有没有人以前做过这个或者知道如何做到这一点? 这是我正在使用的代码:

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

最佳答案

我知道已经过去很长时间了,但只是为了记录一下。 我想我使用 UITableView.backgroundView 找到了更好的解决方案:

UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"lisbon.png"]];

self.tableView.backgroundView = imageView;
[imageView release];

我在 iPhone 上尝试过使用 320x480 的图像尺寸,效果非常好(我也尝试过使用 .jpg)。

关于iPhone - 在 UITableViewController 上设置背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/898351/

相关文章:

ios - UITableView Delegate 在设备和模拟器上的调用方式不同?

ios - 如何在 Today 扩展中调整 UITableView 的大小

ios - 点击时更改 UITableViewCell 高度时动画不稳定

iphone - 从自己的应用程序中查看 PDF 和 Office 文档?

iphone - 替代 Console.WriteLine 进行日志/跟踪?

iphone - 如何批量下载和显示图片而不是一次性下载

安卓 : set background of layout using image path

iphone - 如何将预先存在的 sqlite 文件导入核心数据?

iphone - MPMoviePlayerController 多任务问题

shell - 当我向后台作业发送 SIGCONT 信号时发生了什么?