简体   繁体   中英

WatchKit : Attributed string 'String ' contains NSFontAttributeName that isn't a UIFont (SanFranciscoDisplay-Light). Removed

I am getting the following error

Attributed string 'String ' contains NSFontAttributeName that isn't a UIFont (SanFranciscoDisplay-Light). Removed

Which doesn't make any sense to me because it should be a valid font according to this. http://iosfonts.com . Here is my code.

 atrString = NSAttributedString(string: atrString.string, attributes:
            [NSForegroundColorAttributeName: UIColor.lightGrayColor(),
                NSFontAttributeName:"SanFranciscoDisplay-Light"])

I am trying to access the San Francisco font from my watch kit code. Any tips or suggestions are appreciated.

NSFontAttributeName is a key that should contain a value of type UIFont .

Try UIFont(name: "SanFranciscoDisplay-Light", size: 25) with the size being whatever font size you want.

atrString = NSAttributedString(string: atrString.string, attributes: [NSForegroundColorAttributeName: UIColor.lightGrayColor(), NSFontAttributeName:UIFont(name: "SanFranciscoDisplay-Light", size: 25)])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM