美文网首页
[iOS]使用CYLTabBarController时UITab

[iOS]使用CYLTabBarController时UITab

作者: 汴城码农 | 来源:发表于2021-03-18 14:40 被阅读0次

使用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];
IMG_165C17E1EE30-1.jpeg

相关文章

网友评论

      本文标题:[iOS]使用CYLTabBarController时UITab

      本文链接:https://www.haomeiwen.com/subject/ezoucltx.html