今天在UITabBarController使用自定义图片设置UITabItem时,发现一个问题:
在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 *musicImage = [UIImage imageNamed:@"music.png"]; UIImage *musicImageSel = [UIImage imageNamed:@"musicSel.png"]; musicImage = [musicImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; musicImageSel = [musicImageSel imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; self.musicViewController.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"Music" image:musicImage selectedImage:musicImageSel];
问题解决
相关推荐
自定义UITabbar
iOS 自定义UITabBar中间按钮(OC版), 创建一个自定义的YLTabBar继承自UITabBar
主要为大家详细介绍了iOS自定义UITabBar仿今日头条效果,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
UITabBar 点击当前选中的 item 时触发下拉刷新。 使用 runtime hook UITabBar 的点击事件,不依赖 UITabBarControllerDelegate,支持刷新动画。 https://github.com/xiaopin/UITabBarRefresh.git
主要为大家详细介绍了iOS自定义UITabBar中间按钮,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
UITabBar自定义,顶部曲线,中间按钮突出(OC)
包括tabBarController的基本设置, 自定义tabBar(tabBar中间包含按钮)
UITabBar 点击动画效果,点击UITabBar页面切换的同时,被点击的UITabBar会有一个动画效果,类似于果冻效果
自定义的一个uitabbar ,直接可以用...
ios xcode 7.2.1版本6splus 运行
在小编整理过的文章iOS项目基本框架搭建中,我们详细说明了如何对TabBarItem的图片属性以及文字属性进行一些自定义配置。但是,很多时候,我们需要修改TabBarItem的图片和文字属性之外,还需要自定义TabBarItem的...
高度可定制,摆脱系统的局限性,主要是我只是写了个demo想怎么变都行,不用太局限
自定义UITabBar中间按钮和cell左滑动按钮
1.自定义中间带弧度的UITabBar(参照代码思路可改成其它形状)。 2.TabBar保留系统原有push和pop过渡效果。 3.由于自定义了UITabBar所以就连同TabBarController也一同定义了(用法和系统的很类似)。
一个自定义UITabbarController的tabBar的界面效果,并点击有动画效果移动背景
自定义UITabbar
3、tabBarItem属性来改变tabbar上对应的tab显示内容,tabBarItem包含文字和图片,可以不设置图片,例如UITabBarItem *item = [[UITabBarItem alloc] initWithTitle:@"Second" image:nil tag:1]。 4、UITabBar上最多...