Setting UIFont Weight

8.8k views Asked by At

In iOS 8 in order to get Helvetica Neue in the thin variation the following code would work

UIFont.systemFontOfSize(50, weight: UIFontWeightThin)

In iOS 9 the system font changed to San Francisco, so I can no longer do this. I absolutely must use Helvetia in this app and can't figure out how to set the font weight. This is the code I am currently using.

    timeSelectedLabel.font = UIFont(name: "Helvetica Neue", size: CGFloat(50))

I know there is a constructor which accepts a UIFontDescriptor. Not sure how to use that though. Any thoughts are appreciated!

Note: Before you mark this as duplicate know that the only 2 posts are either unanswered or don't currently work.

2

There are 2 answers

1
Big_Mac On BEST ANSWER

All I had to do was specify the weight after a dash like so.

UIFont(name: "HelveticaNeue-Thin", size: CGFloat(50))
0
Nii Mantse On

In Swift 3, you could simply set this as:

textLabel?.font = UIFont(name: "Avenir-Medium", size: 10)!

There's no need to set the size using the CGFloat parameter.