天天看點

storyboard tabBarItem 添加image和字型顔色問題

<p><span style="font-family: Arial, Helvetica, sans-serif;">/* Images are created with UIImageRenderingModeAutomatic by default. An image with this mode is interpreted as a template image or an original image based on the context in which it is rendered. For example, navigation bars, tab bars, toolbars, and segmented controls automatically treat their foreground images as templates, while image views and web views treat their images as originals. You can use UIImageRenderingModeAlwaysTemplate to force your image to always be rendered as a template or UIImageRenderingModeAlwaysOriginal to force your image to always be rendered as an original.</span></p> */
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);           

複制

1.通過storyboard  添加image和字型的時候,高亮顔色為藍色。

原因:xib預設選中照片mode是系統模式,修改模式即可

解決辦法:修改照片模式為普通模式

UIImage *image = [tabbarVc.tabBarItem.selectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
 self.tabBarItem.selectedImage = image;           

複制

2:tabBarItem字型設定一下即可,方法如下:

[self.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor redColor]} forState:UIControlStateSelected];           

複制