Core Text - NSAttributedString line height done right?

前端 未结 10 764
Happy的楠姐
Happy的楠姐 2020-12-23 09:21

I\'m completely in the dark with Core Text\'s line spacing. I\'m using NSAttributedString and I specify the following attributes on it: - kCTFontAttributeName - kCTParagraph

10条回答
  •  醉梦人生
    2020-12-23 09:35

    This worked for me in Xcode 7.2. iOS 9.2.1. (Swift 2.1.):

      dispatch_async(dispatch_get_main_queue()) { () -> Void in
            let paragraphStyleWithSpacing           = NSMutableParagraphStyle()
            paragraphStyleWithSpacing.lineSpacing   = 2.0 //CGFloat
            let textWithLineSpacing                 = NSAttributedString(string: str, attributes: [NSParagraphStyleAttributeName : paragraphStyleWithSpacing])
            self.MY_TEXT_VIEW_NAME.attributedText   = textWithLineSpacing
        }
    

提交回复
热议问题