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

Schuey999
  • 4,706
  • 7
  • 21
  • 36

1 Answers1

5

You can construct a font using the system constructors:

var foo = UIFont.systemFontOfSize(fontSize: CGFloat)
BaseZen
  • 8,650
  • 3
  • 35
  • 47
  • i just downloaded the SF font from apples website and it looks like its working – Schuey999 Mar 26 '16 at 00:09
  • 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. – BaseZen Mar 26 '16 at 00:11
  • true. My app only supports ios8 on so i might just add an if statement. But I'll see what your code does! – Schuey999 Mar 26 '16 at 00:12
  • yup your code works much better then what I was thinking of doing! Thanks! – Schuey999 Mar 26 '16 at 00:15