我有一个 UITabBar
,每个选项卡都会在点击时更改其颜色。
我希望它是动画的(notSelectedColor 到 SelectedColor 之间的 0.5 秒),我该怎么做?
我正在用这样的颜色重新绘制图像:
func imageWithColor(color: UIColor) -> UIImage {
UIGraphicsBeginImageContextWithOptions(size, false, scale)
let context = UIGraphicsGetCurrentContext()
CGContextTranslateCTM(context, 0.0, size.height)
CGContextScaleCTM(context, 1.0, -1.0)
CGContextSetBlendMode(context, CGBlendMode.Normal)
let rect = CGRect(origin: CGPointZero, size: size)
CGContextClipToMask(context, rect, CGImage)
color.setFill()
CGContextFillRect(context, rect)
let newImage = UIGraphicsGetImageFromCurrentImageContext()
return newImage
}
谢谢!
最佳答案
您可以通过以下代码为标签颜色设置动画:
let tabBar: UITabBar? = self.tabBarController?.tabBar
UIView.transitionWithView(tabBar!, duration: 1.0, options: [.BeginFromCurrentState, .TransitionCrossDissolve], animations: {
self.tabBarController?.tabBar.tintColor = UIColor.purpleColor()
}, completion: nil)
我还为您制作了一个示例项目。下载sample project here .
关于ios - 动画 TabBar 颜色变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38848788/