Change font size of UISegmentedControl

前端 未结 16 1804
死守一世寂寞
死守一世寂寞 2020-11-28 20:54

Can anyone please tell me how can I change the font type and size of UISegmentedControl?

16条回答
  •  旧巷少年郎
    2020-11-28 21:20

    Extension for UISegmentedControl for setting Font Size.

    extension UISegmentedControl {
        @available(iOS 8.2, *)
        func setFontSize(fontSize: CGFloat) {
                let normalTextAttributes: [NSObject : AnyObject]!
                if #available(iOS 9.0, *) {
                    normalTextAttributes = [
                        NSFontAttributeName: UIFont.monospacedDigitSystemFontOfSize(fontSize, weight: UIFontWeightRegular)
                    ]
                } else {
                    normalTextAttributes = [
                        NSFontAttributeName: UIFont.systemFontOfSize(fontSize, weight: UIFontWeightRegular)
                    ]
                }
    
            self.setTitleTextAttributes(normalTextAttributes, forState: .Normal)
        }
     }
    

提交回复
热议问题