[英]Change color of UITabBar Icon
我想将 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 文件。 我不知道为什么我仍然收到错误
我已经遍历了UITabbarController的所有子控制器,然后设置了每个控制器的TabBarItem的颜色或色调,它确实有效。
如果 tabbaritem 有图像,您可以通过以下方式设置其颜色:
var testImage = UIImage(named: "someImageName")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate)
testImageView.tintColor = UIColor.redColor()
testImageView.image = testImage
我认为它无法实现,您可以获取所需颜色的图像并在 UITabbar 中使用它,但是关于更改所有 TabBar 颜色,您可以在 Func 的 AppDelegate 中使用以下内容:
didFinishLaunchingWithOptions
要添加的行:
UITabBar.appearance().barTintColor = #colorLiteral(red: 0.2000651062, green: 0.1960035861, blue: 0.2000851929, alpha: 1)
UITabBar.appearance().tintColor = #colorLiteral(red: 0.2000651062, green: 0.1960035861, blue: 0.2000851929, alpha: 1)
UITabBar.appearance().unselectedItemTintColor = #colorLiteral(red: 0.7415059209, green: 0.5448099971, blue: 0.5051562786, alpha: 1)
注意:您可以根据您的应用程序更改颜色
检查图像: https : //i.stack.imgur.com/wESVH.png
并有一个快乐的编码日
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.