大佬教程收集整理的这篇文章主要介绍了使用Swift Xcode 6的默认选项卡栏项目颜色,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
每个(默认)选项卡栏项均由文本和图标组成。通过指定外观可以很容易地全局更改文本颜色:
// you can add this code to you AppDelegate application:dIDFinishLaunchingWithOptions:
// or add it to vIEwDIDLoad method of your TabbarController class
UITabbarItem.appearance().settitleTextAttributes([NSForegroundcolorAttributename: UIcolor.magentacolor()], forState:.normal)
UITabbarItem.appearance().settitleTextAttributes([NSForegroundcolorAttributename: UIcolor.redcolor()], forState:.SELEcted)
对于图像,情况要复杂一些。您不能全局定义它们的外观。您应该在TabbarController类中重新定义它们。将下面的代码添加到vIEwDIDLoad
您的TabbarController
类的方法中:
for item in self.tabbar.items as [UITabbarItem] {
if let image = item.image {
item.image = image.imageWithcolor(UIcolor.yellowcolor()).imageWithRenderingMode(.AlwaysOriginal)
}
}
众所周知imageWithcolor(...)
,UIImage类中没有方法。所以这是扩展实现:
// Add anywhere in your app
extension UIImage {
func imageWithcolor(Tintcolor: UIcolor) -> UIImage {
UIGraphicsBeginImageContextWithOptions(self.size, false, self.scalE)
let context = UIGraphicsGetCurrentContext() as CGContextRef
CGContextTranslateCTM(context, 0, self.size.height)
CGContextScaleCTM(context, 1.0, -1.0);
CGContextSetBlendMode(context, .normal)
let rect = CGRectMake(0, 0, self.size.wIDth, self.size.height) as CGRect
CGContextClipToMask(context, rect, self.CGImagE)
Tintcolor.setFill()
CGContextFillRect(context, rect)
let newImage = UIGraphicsGetimageFromCurrentimageContext() as UIImage
UIGraphicsEndImageContext()
return newImage
}
}
@H_618_0@解决方法
环境:-Xcode 6 beta 4-Swift语言-iOS选项卡式应用程序(默认xCode项目)
如何将选项卡的默认灰色更改为其他颜色?(最好是全球)
就我的研究而言,我需要以某种方式将每个选项卡的图像渲染模式更改为“原始”渲染模式,但是我不知道如何
以上是大佬教程为你收集整理的使用Swift Xcode 6的默认选项卡栏项目颜色全部内容,希望文章能够帮你解决使用Swift Xcode 6的默认选项卡栏项目颜色所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。