storyboard创建的选项卡,图片颜色固定,字体颜色固定。可以说完全没法用,查阅了好久的API和资料才找到修改的办法。
将UITabbarItem连线到FirstVIEwController
代码如下:
//// FirstVIEwController.swift// demo//// Created by sunger on 15/3/24.// copyright (c) 2015年 sunger. All rights reserved.//import UIKitclass FirstVIEwController: UIVIEwController { @IBOutlet weak var tab1: UITabbarItem! overrIDe func vIEwDIDLoad() { super.vIEwDIDLoad() // Do any additional setup after loading the vIEw,typically from a nib. //这里修改图片颜色,使得图片和原图颜色一致 tab1.image=UIImage(named: "tab1")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal); //这里修改字体颜色 var attributes = [NSForegroundcolorAttributename: UIcolor(red: 220.0/255.0,green: 104.0/255.0,blue: 1.0/255.0,Alpha: 1.0),NSFontAttributename: UIFont(name: "Heiti SC",size: 24.0)!] tab1.setTitleTextAttributes(attributes,forState: UIControlState.Selected) } overrIDe func dIDReceiveMemoryWarning() { super.dIDReceiveMemoryWarning() // dispose of any resources that can be recreated. }}
主要参考官方API和如下几篇文章;
1.修改图片颜色
2.修改字体颜色
http://www.cnblogs.com/xgbzsc/archive/2013/01/16/2862611.HTML
http://blog.csdn.net/willyang519/article/details/38855719
http://stackoverflow.com/questions/7810563/how-do-you-use-setTitletextattributesforstate-in-uibaritem
最后实现如下效果
总结
以上是内存溢出为你收集整理的swift UITabBarItem修改字体颜色和图标颜色全部内容,希望文章能够帮你解决swift UITabBarItem修改字体颜色和图标颜色所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)