【发布时间】:2015-03-28 18:29:31
【问题描述】:
我创建了一个 UITabBarController 类
我创建了两个视图控制器并为每个控制器设置了标题属性
我想更改标签中文本标签的大小和颜色
我已经设置了标签颜色和框架使用
UITabBar.appearance().barTintColor = UIColor.blueColor()
tabBar.frame = CGRectMake(0, 0, view.frame.width, 100)
现在为了调整选项卡,我尝试了以下各项
UITabBarItem.appearance().setTitleTextAttributes(NSDictionary(object: UIColor.whiteColor(), forKey: NSForegroundColorAttributeName), forState: UIControlState.Normal)
将文本颜色更改为白色
UITabBarItem.appearance().setTitleTextAttributes(NSDictionary(object: UIColor.whiteColor(), forKey: NSForegroundColorAttributeName), forState: UIControlState.Normal)
UITabBarItem.appearance().setTitleTextAttributes(NSDictionary(object: UIFont(name: "Helvetica", size: 16.0)!, forKey: NSFontAttributeName), forState: UIControlState.Normal)
那只是改变了文本的大小,而不是颜色!
UITabBarItem.appearance().setTitleTextAttributes(NSDictionary(objects: [NSForegroundColorAttributeName, NSFontAttributeName], forKeys: [UIColor.whiteColor(), UIFont(name: "Helvetica", size: 16.0)!]), forState: UIControlState.Normal)
// OR
var attributes = NSDictionary(objects: [NSForegroundColorAttributeName, NSFontAttributeName], forKeys: [UIColor.whiteColor(), UIFont(name: "Helvetica", size: 16.0)!])
UITabBarItem.appearance().setTitleTextAttributes(attributes, forState: UIControlState.Normal)
最后一点什么也没做,既没有设置标签文本的颜色,也没有设置标签文本的大小
更新-----
更准确地说,上面的代码都是在viewWillAppear的UITabBarController子类中尝试的
此外,我很好奇如何制作整个选项卡(可选项卡),而不仅仅是文本标签的一部分,还在选项卡之间添加某种行分隔符
【问题讨论】:
标签: ios swift uiviewcontroller uitabbarcontroller uitabbaritem