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

3
如何更改分段控件标题的字体大小?
如图所示: enter image description here

6
请参考此链接,它可能有帮助:https://dev59.com/MV4c5IYBdhLWcg3wap3z - Anbu.Karthik
thank you! @Anbu.Karthik - Aldo Lazuardi
请考虑将帖子发布为@Anbu的答案。 - Stephan Kristyn
@StephanKristyn 他们确实发布了一个答案,但由于只有链接而被删除为NAA。 - AStopher
3个回答

2

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

1.) 使用UISegmentControlappearance代理更新字体。这将为您的应用程序中所有UISegmentContol对象更新相同的属性。 您不需要在每个视图控制器中设置,只需在appDelegatedidFinishLaunching:中设置即可。

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

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

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

1
你可以尝试使用这个:
yourSegControl.setTitleTextAttributes([ NSFontAttributeName: UIFont(name: "YourFont", size: 18.0)! ], forState: .Normal)

您可以在苹果文档中了解更多信息。


0

试试这个

   var attributes = NSDictionary(object: UIFont(name: "HelveticaNeue", size: 12.0)!, forKey: NSFontAttributeName)
    segmentControl.setTitleTextAttributes(attributes, forState: .Normal)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接