5

有没有人尝试过快速使用外观代理?

这种语法不起作用,有没有人想出如何在segmentedControl或UITabBar等控件上设置标题文本属性?我想我很接近

segmentedControl.titleTextAttributesForState(UIControlState.Normal) = 
NSDictionary(objects: [UIFont(name: fontFamilyRegular, size: 16.0)], 
forKeys: [NSFontAttributeName])
4

3 回答 3

10

这应该这样做:

segmentedControl.setTitleTextAttributes([
    NSFontAttributeName: UIFont(name: "Helvetica", size: 16.0)!,
    NSForegroundColorAttributeName: UIColor.blueColor()
    ], forState: UIControlState.Normal)
于 2014-06-03T14:38:42.827 回答
3

确保解开字体 (!)

let font = UIFont(name: "HelveticaNeue-Light", size:15.0)!
UIBarButtonItem.appearance().setTitleTextAttributes([NSFontAttributeName:font,NSForegroundColorAttributeName:UIColor.redColor()], forState: UIControlState.Normal)
于 2015-01-26T16:53:49.790 回答
1

对于 XCode 6.1,试试这个:

UITabBarItem.appearance().setTitleTextAttributes(NSDictionary(object: UIFont(name: "Helvetica", size: 16.0)!, forKey: NSFontAttributeName), forState: UIControlState.Normal)
于 2014-11-15T18:24:26.867 回答