使用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
网友评论