Bil*_*ill 10 iphone background image uitableview
我见过一些iPhone应用程序使用自定义图像作为分组UITableView的背景,而不是标准的灰色线条.
这是如何实现的?
tbo*_*one 24
这对我有用(一旦我弄清楚就相当简单;)
1)在app delegate中添加一个视图,并使其成为窗口的子视图:
UIView *bgView = [[UIView alloc]initWithFrame:window.frame];
bgView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"screenBG.png"]];
[window addSubview:bgView];
[bgView release];
Run Code Online (Sandbox Code Playgroud)
2)在每个视图控制器.m文件上,在ViewDidLoad下,将该特定视图的背景颜色设置为透明(因此上面创建的其他bgView将显示):
self.view.backgroundColor = [UIColor clearColor];
Run Code Online (Sandbox Code Playgroud)
在我的例子中,步骤2中的视图控制器是tableviewcontroller.看起来很棒.
顺便说一句,在每个视图控制器中执行以下操作并不能很好地工作:
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"screenBG.png"]];
Run Code Online (Sandbox Code Playgroud)
请按照上面的步骤1和2进行操作.
希望这会有所帮助,Tbone
小智 9
试试这个
- (void) viewDidLoad {
[super viewDidLoad];
self.tableView.backgroundColor = [UIColor clearColor];
self.view.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed:@"wallpaper.png"]];
self.tableView.opaque = NO;
}
Run Code Online (Sandbox Code Playgroud)
在另一个项目(使用 2.2.1 开发)中,我通过将UITableView'背景不透明度设置为 0%,然后UIImageView使用 Interface Builder 在其后面简单地分层。这使我能够拥有固定的背景,而不管表状态如何。您还可以将 的背景设置UITableView为图像,但背景会随表格一起滚动。(我现在手边没有代码,但我不久前在苹果开发者论坛上得到了提示)。
请注意,这可能会导致一些性能问题。Apple 尽可能不鼓励使用透明度,因为 3GS 之前的型号上的 GPU 并不是特别强大。