如何更改 iOS7 中的未选定的 tabbaritem 颜色
2015-11-23 09:51
316 查看
此代码在 iOS 7 上工作。
[[UITabBarItem appearance]
setTitleTextAttributes:@{NSFontAttributeName : [UIFont
fontWithName:@"HelveticaNeue-Bold" size:10.0f],
NSForegroundColorAttributeName : [UIColor
colorWithRed:.5 green:.5 blue:.5 alpha:1]
} forState:UIControlStateNormal];
如你所设置的前景色。
影响也非选定 tabbar 图标:
[[UITabBarItem
appearance] setTitleTextAttributes:[NSDictionary
dictionaryWithObjectsAndKeys:[UIColor greenColor],
UITextAttributeTextColor, nil]
forState:UIControlStateNormal];
如果它不工作的唯一方法是用图像的选定和未选定状态:
// set selected and unselected icons
UITabBarItem *item = [self.tabBar.items objectAtIndex:0];
// this way, the icon gets rendered as it is (thus, it needs to be green in this example)
item.image = [[UIImage imageNamed:@"unselected-icon.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
// this icon is used for selected tab and it will get tinted as defined in self.tabBar.tintColor
item.selectedImage = [UIImage imageNamed:@"selected-icon.png"];
[[UITabBarItem appearance]
setTitleTextAttributes:@{NSFontAttributeName : [UIFont
fontWithName:@"HelveticaNeue-Bold" size:10.0f],
NSForegroundColorAttributeName : [UIColor
colorWithRed:.5 green:.5 blue:.5 alpha:1]
} forState:UIControlStateNormal];
如你所设置的前景色。
影响也非选定 tabbar 图标:
[[UITabBarItem
appearance] setTitleTextAttributes:[NSDictionary
dictionaryWithObjectsAndKeys:[UIColor greenColor],
UITextAttributeTextColor, nil]
forState:UIControlStateNormal];
如果它不工作的唯一方法是用图像的选定和未选定状态:
// set selected and unselected icons
UITabBarItem *item = [self.tabBar.items objectAtIndex:0];
// this way, the icon gets rendered as it is (thus, it needs to be green in this example)
item.image = [[UIImage imageNamed:@"unselected-icon.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
// this icon is used for selected tab and it will get tinted as defined in self.tabBar.tintColor
item.selectedImage = [UIImage imageNamed:@"selected-icon.png"];
相关文章推荐
- IOS多线程编程的3种实现方法
- iOS开发中CAlayer层的属性以及自定义层的方法
- IOS开篇
- iOS 阿拉伯数字转汉字(1转一)
- iOS中发送短信/发送邮件的实现 韩俊强的博客
- iOS中发送短信/发送邮件的实现 韩俊强的博客
- iOS开发进阶-实现多线程的3种方法
- iOS---自动布局
- 自己对于instancetype的理解和应用iOS开发的过程
- ios 集成环信的坑
- iOS之[多线程:GCD:Dispatch]
- iOS之[多线程:NSThread]
- iOS之[多线程:NSOperation]
- iostat命令详解
- iOS 9音频应用播放音频之播放控制暂停停止前进后退的设置
- iOS之nib、xib及storyboard的区别及storyboard的加载过程
- 蓝懿ios 技术内容交流和学习心得 11.22
- NSString的详细用法(函数说明)
- 开始iOS 7中自动布局教程(一) 从iOS6讲到iOS7以后
- iOS9下使用FMDB出现Undefined symbols for architecture i386: "_NSFileTypeForHFSTypeCode",