在View里放背景图片就像很多其它iOS编程一样有很多方法:
使用UIColor的 colorWithPatternImage来设置背景色;
在view中添加一个UIImageView作为一个子View。
如果你使用全画幅的背景图,你就必须使用UIImageView因为UIColor的colorWithPatternImage是用来创建小的重复的图片作为背景的。这种情形下使用UIImageView可以节约不少的内存:
|
1
2
3
|
// You could also achieve the same result in Interface BuilderUIImageView *backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"background"]];[self.view addSubview:backgroundView]; |
如果你用小图平铺来创建背景,你就需要用UIColor的colorWithPatternImage来做了,它会更快地渲染也不会花费很多内存:
|
1
|
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background"]]; |
本文介绍了两种在iOS应用中设置视图背景图片的方法:使用UIColor的colorWithPatternImage实现小图平铺背景,以及通过UIImageView添加全尺寸背景图。前者适用于小图标平铺的情况,后者适合全屏显示的大图。
897

被折叠的 条评论
为什么被折叠?



