1,tabBarItem图片的推荐尺寸和最大支持尺寸
下面是标签栏(UITabBar)中tab按钮图标分别在1x、2x、3x下不会压缩变形的尺寸:
下面是在2x下,左边使用50 x 50的图片,右边使用64 x 64的图片,大家可以比较下:
import UIKit
class MainTabViewController:UITabBarController
{
override func viewDidLoad()
{
super.viewDidLoad()
//一共包含了两个视图
let qqView = View1ViewController()
qqView.title = "QQ"
let androidView = View1ViewController()
androidView.title = "skype"
//分别声明两个视图控制器
let qq = UINavigationController(rootViewController:qqView)
qq.tabBarItem.image = UIImage(named:"qq")
let android = UINavigationController(rootViewController:androidView)
android.tabBarItem.image = UIImage(named:"skype")
self.viewControllers = [qq,android]
//默认选中的是qq视图
self.selectedIndex = 0
}
}
2,修改图片和文字的颜色
//图片文字一起变色
self.tabBar.tintColor = UIColor.orangeColor()
(2)只改变文字颜色
//改变文字颜色
UITabBarItem.appearance().setTitleTextAttributes(
[NSForegroundColorAttributeName: UIColor.grayColor()], forState:.Normal)
UITabBarItem.appearance().setTitleTextAttributes(
[NSForegroundColorAttributeName: UIColor.orangeColor()], forState:.Selected)
(3)只改变图片颜色
self.tabBar.tintColor = UIColor.orangeColor()
//文字颜色还原
UITabBarItem.appearance().setTitleTextAttributes(
[NSForegroundColorAttributeName: self.view.tintColor], forState:.Selected)
3,选中时、不选中时使用不同图片
默认标签选中、不选中都使用的是同一个图片,只是颜色不同。我们也可使用两张不同图片表示两种状态。
qq.tabBarItem = UITabBarItem(title: "QQ", image: UIImage(named: "qq"),
selectedImage: UIImage(named: "qq_active"))
android.tabBarItem = UITabBarItem(title: "Android", image: UIImage(named: "android"),
selectedImage: UIImage(named: "android_active"))
4,使用图片的原始颜色
默认不管原图是什么颜色,渲染器都会将渲染成单一颜色,虽说符合现在扁平化的趋势,但有时我们还是想要使用图片原来的样子。
如下样例,标签选中时使用不着色的原始图片(未选中仍然渲染成灰色,当然也可以使用原始图片)
qq.tabBarItem = UITabBarItem(title: "QQ", image: UIImage(named: "qq_color"),
selectedImage: UIImage(named: "qq_color")?.imageWithRenderingMode(.AlwaysOriginal))
android.tabBarItem = UITabBarItem(title: "Android", image: UIImage(named: "android_color"),
selectedImage: UIImage(named: "android_color")?.imageWithRenderingMode(.AlwaysOriginal))
敢达决战官方正版 安卓版v6.7.9
下载敢达决战 安卓版v6.7.9
下载像素火影骨架佐助 (Perseverance Fire Shadow)手机版v1.16
下载要塞英雄 安卓版v33.20.0-39082670-Android
下载梦想城镇vivo最新版本 安卓版v12.0.1
梦想城镇vivo版是这款卡通风模拟经营类手游的渠道服版本,玩
怦然心动的瞬间 安卓版v1.0
怦然心动的瞬间是一款真人向的恋爱互动游戏,在游戏中玩家将扮演
曼尼汉堡店游戏 安卓版v1.0.3
曼尼汉堡店是一款非常好玩的精品恐怖类型冒险游戏,在这款游戏中
现代总统模拟器去广告版 安卓版v1.0.46
现代总统模拟器是一款休闲养成类游戏,可能对于不少的玩家来说都
现代总统模拟器付费完整版 安卓版v1.0.46
现代总统模拟器高级版在商店是需要付费的,相对于普通版本,高级