UIView只接受UIColor作为setBackgroundColor的参数,但是我们有时候需要用一张图片UIImage来作为UIView的背景,这个时候就需要将UIImage转换为UIColor。这样就可以用UIImage来作为UIView的背景图片了。
1 2 3 4 |
-(void)imageToColor{ UIColor *bgColor = [UIColor colorWithPatternImage:img]; [uiView setBackgroundColor:bgColor]; } |
Welcome to WordPress. This is your first post. [[” ] Edit or delete it, then start blogging!