storyboard tabBarItem 添加image和字体颜色问题

2019-01-15 11:01:34 浏览数 (1)

代码语言:javascript复制
<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是系统模式,修改模式即可

解决办法:修改照片模式为普通模式

代码语言:javascript复制
 UIImage *image = [tabbarVc.tabBarItem.selectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
 self.tabBarItem.selectedImage = image;

2:tabBarItem字体设置一下即可,方法如下:

代码语言:javascript复制
[self.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor redColor]} forState:UIControlStateSelected];

0 人点赞