首页 > 代码库 > #iOS开发常用方法集锦#如何为UIView添加居中背景

#iOS开发常用方法集锦#如何为UIView添加居中背景

?本文永久地址为?http://www.cnblogs.com/ChenYilong/p/4103050.html,转载请注明出处。

Evernote印象笔记:https://app.yinxiang.com/shard/s22/sh/2fe4cb0f-26cb-47ce-8569-bb45451cb7b8/6118d5a054003de9


//如何为UIView添加居中背景

#define kBackgroundImageCenterForView(ViewName,imageName)\ UIGraphicsBeginImageContext(self.view.frame.size);\ [[UIImage imageNamed:imageName] drawInRect:ViewName.bounds];\ UIImage *image = UIGraphicsGetImageFromCurrentImageContext();\ UIGraphicsEndImageContext();\ ViewName.backgroundColor = [UIColor colorWithPatternImage:image]; 

用法

 kBackgroundImageCenterForView(_backGestureView,@"CircleBack") 

另外,附上平铺图片

#define kBackgroundImageResizedForView(ViewName,imageName)\ UIImage *highlightedBgImage = [UIImage resizedImage:imageName];\ ViewName.backgroundColor = [UIColor colorWithPatternImage:imageName]; 

参考

http://stackoverflow.com/questions/8077740/how-to-fill-background-image-of-an-uiview 

end


?

?本文永久地址为?http://www.cnblogs.com/ChenYilong/p/4103050.html,转载请注明出处。

?



#iOS开发常用方法集锦#如何为UIView添加居中背景