iOS7修改UITabBar文本颜色以及解决自定义选中图片显示为默认蓝色的问题
2015-05-22 10:30
856 查看
修改UITabbar背景色和文本颜色和大小:
解决自定义选中图片显示为默认蓝色的问题:
在iOS7以上的手机中,第一个Tab的选中图一直显示的是系统默认的蓝色图,查看了一下UITabItem的头文件,发现下面的内容:
意思是,如果不希望使用系统颜色,需要对图片加上属性UIImageRenderingModeAlwaysOriginal
所以按此方式实验,代码如下:
[[UITabBar appearance] setBackgroundColor:UIColorFromRGB(0xeff3f4)]; [[UITabBarItem appearance] setTitleTextAttributes:@{ NSFontAttributeName : [UIFont fontWithName:@"HelveticaNeue" size:12.5f], NSForegroundColorAttributeName : UIColorFromRGB(0x929292) } forState:UIControlStateNormal]; [[UITabBarItem appearance] setTitleTextAttributes:@{ NSForegroundColorAttributeName : UIColorFromRGB(0xFF87C332) } forState:UIControlStateSelected];
解决自定义选中图片显示为默认蓝色的问题:
在iOS7以上的手机中,第一个Tab的选中图一直显示的是系统默认的蓝色图,查看了一下UITabItem的头文件,发现下面的内容:
/* The unselected image is autogenerated from the image argument. The selected image is autogenerated from the selectedImage if provided and the image argument otherwise. To prevent system coloring, provide images with UIImageRenderingModeAlwaysOriginal (see UIImage.h) */ - (instancetype)initWithTitle:(NSString *)title image:(UIImage *)image tag:(NSInteger)tag; - (instancetype)initWithTitle:(NSString *)title image:(UIImage *)image selectedImage:(UIImage *)selectedImage NS_AVAILABLE_IOS(7_0); - (instancetype)initWithTabBarSystemItem:(UITabBarSystemItem)systemItem tag:(NSInteger)tag;
意思是,如果不希望使用系统颜色,需要对图片加上属性UIImageRenderingModeAlwaysOriginal
所以按此方式实验,代码如下:
UIImage *iconImage = [UIImage imageNamed:@"icon.png"]; UIImage *iconImageSel = [UIImage imageNamed:@"icon_selected.png"]; iconImage = [iconImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; iconImageSel = [iconImageSel imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; self.musicViewController.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"Music" image: iconImage selectedImage: iconImageSel];
相关文章推荐
- [iOS]iOS7+ UITabBar修改选中图片显示为默认蓝色的问题解决方法,去除UITabbar顶部一像素横线
- iOS7 UITabBar自定义选中图片显示为默认蓝色的Bug
- 解决iOS8以上系统下app底部UITabBarItem上自定义的背景色和图片,在首次启动或push之后再pop回去会变成系统默认颜色-蓝色问题
- iOS7 UITabBar自定义选中图片显示为默认蓝色的Bug
- iOS7 UITabBar自定义选中图片显示为默认蓝色的Bug
- iOS7 UITabBar自定义选中图片显示为默认蓝色的Bug
- OS7 UITabBar自定义选中图片显示为默认蓝色的Bug
- xcode6.1 自定义tabbar与poptoview产生重叠问题以及ios8上自定义tabbar图片显示颜色是系统颜色问题
- shareSDK分享平台分享内容出去显示“来自XXX”的问题及其如何修改分享菜单的背景图片以及调用无UI方法自定义UI分享
- Swift之修改选中TabBarItem图片时显示的默认蓝色
- iOS-UITabBar的使用包括选中前后使用不同的自定义颜色以及图标颜色的改变问题)imageView,titles
- IOS7怎么修改Navigation Bar上的返回按钮文本颜色,箭头颜色以及导航栏按钮的颜色
- 想把图片当背景,但是其他控件背景设为透明色后,显示的是背景颜色的问题解决
- UITabBar-UITabBarItem的选中图片未按照原图样式显示的问题mark
- CTAssetsPickerController 选中图片不显示对号的问题解决
- 系统的Tabbar的默认选中图标显示蓝色,实际图片为橙色
- 使用系统UITabbarItem自定义图片显示原本颜色和自定义文字颜色
- 关于标签栏(UITabBarItem)的系统颜色和图片以及标题颜色的问题
- 解决Android启动显示空白界面的问题,自定义进入软件前的背景图片。
- 修改UITabBarController字体颜色 图片大小颜色的小问题