4
let attributedText: NSMutableAttributedString = NSMutableAttributedString(string: text, attributes: [NSFontAttributeName: UIFont(name: "San Francisco", size: 14.0)!])

Using the code above, when I run my app it crashes because it cannot find the "San Francisco" font. But isn't that the system font for iOS 9? How can I use the system font in an attributed string?

I am using Swift 2.2

1 Answer 1

5

You can construct a font using the system constructors:

var foo = UIFont.systemFontOfSize(fontSize: CGFloat)
Sign up to request clarification or add additional context in comments.

4 Comments

i just downloaded the SF font from apples website and it looks like its working
But this actually answers your question. In iOS8 and earlier the system font is not San Francisco, rather Helvetica Neue Light. Depends on your goal.
true. My app only supports ios8 on so i might just add an if statement. But I'll see what your code does!
yup your code works much better then what I was thinking of doing! Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.