我们可以给任何uiview一些背景图片吗?

问题描述:

我需要为我的视图设置一些背景图像。我怎样才能做到这一点?我们可以给任何uiview一些背景图片吗?

最简单的方法是将imageView添加到您的视图与适当的背景图像。只要确保是最低的z顺序子视图通过增加它的第一或致电[view sendSubviewToBack:backGroundView];

作为替代方案,您可以设置图片为您的视图的层内容:

#import <QuartzCore/QuartzCore.h> 

...  
view.layer.contents = yourImage.CGImage; 

view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background.png"]]; 
+0

哎呀,忘了这个选项。好一个 – Vladimir 2010-10-26 11:38:32