著色(Tint Color)是iOS7界面中的一個重大改變焊傅,你可以設(shè)置一個UIImage再渲染時是否使用當前視圖的TintColor建芙。iOS7中UIImage新增了一個只讀屬性:randeringMode奋单,對應(yīng)的還有一個新增方法:imageWithRenderingMode:闻察。
// Create a version of this image with the specified rendering mode. By default, images have a rendering mode of UIImageRenderingModeAutomatic.
- (UIImage *)imageWithRenderingMode:(UIImageRenderingMode)renderingMode NS_AVAILABLE_IOS(7_0);
@property(nonatomic, readonly) UIImageRenderingMode renderingMode NS_AVAILABLE_IOS(7_0);
它使用UIImageRenderingMode枚舉值來設(shè)置圖片的renderingMode屬性捆探。該枚舉中包含下列值:
typedef NS_ENUM(NSInteger, UIImageRenderingMode) {
UIImageRenderingModeAutomatic, // Use the default rendering mode for the context where the image is used
UIImageRenderingModeAlwaysOriginal, // Always draw the original image, without treating it as a template
UIImageRenderingModeAlwaysTemplate, // Always draw the image as a template image, ignoring its color information
} NS_ENUM_AVAILABLE_IOS(7_0);
UIImageRenderingModeAutomatic // 根據(jù)圖片的使用環(huán)境和所處的繪圖上下文自動調(diào)整渲染模式
UIImageRenderingModeAlwaysOriginal // 始終繪制圖片原始狀態(tài)奔誓,不使用TintColor
UIImageRenderingModeAlwaysTemlate // 始終根據(jù)Tint Color 繪制圖片斤吐,忽略圖片的顏色信息
renderingMode屬性的默認值是UIImageRenderingModeAutomatic,即UIImage是否使用TintColor取決于它顯示的位置
什么情況下使用厨喂?
某些時候和措,在為某些空間添加圖片的時候,會不顯示圖片蜕煌,只顯示控件的tint color派阱,故需要將其著色改為原始狀態(tài),才可以顯示出來圖片斜纪。
UIImage *pic = [UIImage imageNamed:@"qq.png"];
pic = [pic imageWithRenderingMode:UIImageRenderingModealwaysOriginal];