【发布时间】:2015-02-11 22:33:52
【问题描述】:
我想将 UI 选项卡栏图标颜色更改为以下值:红色:0.75、绿色:1.0、蓝色:1.0、Alpha:1.0,并且在未选择图标时更改为白色。
直到现在我还以为你是这样做的:
UITabBarItem.appearance().finishedSelectedImage([NSForegroundColorAttributeName: UIColor(red: 0.75, green: 1.0, blue: 1.0, alpha: 1.0)], forState: UIControlState.Selected)
UITabBarItem.appearance().finishedUnselectedImage([NSForegroundColorAttributeName: UIColor.whiteColor()], forState: UIControlState.Normal)
上面的代码在我的委托中。
现在我已经输入了这段代码:
import UIKit
class UITabBarViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
var testImage = UIImage(named: "22274")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate)
testImageView.tintColor = UIColor.redColor()
testImageView.image = testImage
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
进入我的标签栏视图控制器 cocco touch 文件。我不知道为什么我仍然收到错误
【问题讨论】:
-
是否有您想要着色的图像,或者只是文本?
-
你设置了tint color
-
我目前没有图像,但我正在谈论未来。我可以在“更多”标签栏图标中看到它是灰色的,并且与我的蓝色背景不匹配。 @DánielNagy
-
那我该如何设置图标的颜色呢? @soulshined
-
stackoverflow.com/questions/10755576/… 这是一个客观的 c 示例,但请看第二个答案,而不是接受的答案
标签: ios swift uitabbarcontroller uitabbar uicolor