how to set attributes in NSAttributedString in iOS?

随声附和 提交于 2019-12-02 05:03:35
SaldaVonSchwartz

I found it!

basically, turns out the string constant for the dictionary key I should been using is kCTFontAttributeName

This whole thing is a show...

The NS constants and full attributedString support will be there. Not yet in iOS5 though.

The CoreText constants do work and CTFontRef is the way I use it as well. The first block of your code should work. Can you verify your other bits of code that the problem ain't elsewhere.

do this way:

let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.alignment = .center


let attributes = [NSParagraphStyleAttributeName :  paragraphStyle,
                  NSFontAttributeName :   UIFont.systemFont(ofSize: 24.0),
                  NSForegroundColorAttributeName : UIColor.blue,
                  ]

let attrString = NSAttributedString(string: "Stop\nall Dance",
                               attributes: attributes)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!