1、有的时候我们需要将一张图片平铺在View上当做背景。
其实实现起来很简单。代码
+ (UIColor *)colorWithPatternImage:(UIImage *)image
使用也很简单:
1
2
3
4
5
|
- (
void
)viewDidLoad {
[super viewDidLoad];
UIImage *patternImage = [UIImage imageNamed:@
"pattern.png"
];
self.view.backgroundColor = [UIColor colorWithPatternImage:patternImage];
}
|
2、
在进行ios开发时,我门有时候会为了节省安装包大小而采取用局部图片平铺作为背景图片。
做法:
1:在view的draeRect里面使用UIIMage的方法:
drawAsPatternInRect:
第一种做法,没有经过测试,只是参考网上的做法,第二种方式一般情况下不用创建新的UIView,而可以只是直接设置背景色,当设置背景色的做法不起作用的的时候,可以考虑像上如做法设置背景View