[iOS]使用CYLTabBarController时UITabBarItem实心问题

使用TabBarController时,注意设置image的UIImageRenderingModeAlwaysOriginal属性,否则只显示图片轮廓(被转换过了),图片不能正常显示

- (NSArray *)tabBarItemsAttributesForTabBar {
    
    UIImage *buy_normal_icon = [UIImage imageNamed:@"buy_normal"];
    buy_normal_icon = [buy_normal_icon imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    // lottie动画的json文件来自于NorthSea, respect!
    CGFloat firstXOffset = -12/2;
    NSDictionary *firstTabBarItemsAttributes = @{
                                                 CYLTabBarItemTitle : @"首页",
                                                 CYLTabBarItemImage : [UIImage imageNamed:@"home_normal"],  /* NSString and UIImage are supported*/
                                                 CYLTabBarItemSelectedImage : @"home_highlight",  /* NSString and UIImage are supported*/
                                                 CYLTabBarItemTitlePositionAdjustment: [NSValue valueWithUIOffset:UIOffsetMake(firstXOffset, -2.5)]
                                                 };
    CGFloat secondXOffset = (-25+2)/2;
    NSDictionary *secondTabBarItemsAttributes = @{
                                                  CYLTabBarItemTitle : @"拍卖",
                                                  CYLTabBarItemImage : buy_normal_icon,
                                                  CYLTabBarItemSelectedImage : [UIImage imageNamed:@"buy_highlight"],
                                                  CYLTabBarItemTitlePositionAdjustment: [NSValue valueWithUIOffset:UIOffsetMake(secondXOffset, -2.5)],
                                                  };
    
    NSDictionary *thirdTabBarItemsAttributes = @{
                                                 CYLTabBarItemTitle : @"交易",
                                                 CYLTabBarItemImage : [UIImage imageNamed:@"sell_normal"],
                                                 CYLTabBarItemSelectedImage : @"sell_highlight",
                                                 CYLTabBarItemTitlePositionAdjustment: [NSValue valueWithUIOffset:UIOffsetMake(-secondXOffset, -2.5)],
                                                 };
    NSDictionary *fourthTabBarItemsAttributes = @{
                                                  CYLTabBarItemTitle : @"我的",
                                                  CYLTabBarItemImage :[UIImage imageNamed:@"mine_normal"],
                                                  CYLTabBarItemSelectedImage : @"mine_highlight",
                                                  CYLTabBarItemTitlePositionAdjustment: [NSValue valueWithUIOffset:UIOffsetMake(-firstXOffset, -2.5)]
                                                  };
    NSArray *tabBarItemsAttributes = @[
                                       firstTabBarItemsAttributes,
                                       secondTabBarItemsAttributes,
                                       thirdTabBarItemsAttributes,
                                       fourthTabBarItemsAttributes
                                       ];
    return tabBarItemsAttributes;
}

核心代码

    UIImage *buy_normal_icon = [UIImage imageNamed:@"buy_normal"];
    buy_normal_icon = [buy_normal_icon imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
[iOS]使用CYLTabBarController时UITabBarItem实心问题_第1张图片
IMG_165C17E1EE30-1.jpeg

你可能感兴趣的:([iOS]使用CYLTabBarController时UITabBarItem实心问题)