如何更改UISegmentedcontrol标题的字体大小?

时间:2016-02-11 12:48:41

标签: ios swift uisegmentedcontrol

如何更改segmentedcontrol标题的字体大小?

enter image description here

3 个答案:

答案 0 :(得分:2)

您可以使用两种方法更改字体大小。

1。)使用appearance UISegmentControl代理更新字体。这将为您应用的UISegmentContol的所有对象更新相同的属性。 您不需要在每个viewController中进行设置,只需在didFinishLaunching:的{​​{1}}中设置。

appDelegate

2。)更新特定段控件的字体。

var attr = NSDictionary(object: UIFont(name: "yourFontName", size: 12.0)!, forKey: NSFontAttributeName)
UISegmentedControl.appearance().setTitleTextAttributes(attr, forState: .Normal)

答案 1 :(得分:1)

你可以试试这个:

yourSegControl.setTitleTextAttributes([ NSFontAttributeName: UIFont(name: "YourFont", size: 18.0)! ], forState: .Normal)

您可以在apple docs

中找到更多信息

答案 2 :(得分:0)

试试这个




  var attributes = NSDictionary(对象:UIFont(名称:“HelveticaNeue”,大小:12.0)!,forKey:NSFontAttributeName)&# XA; segmentControl.setTitleTextAttributes(attributes,forState:.Normal)