Core Text - NSAttributedString line height done right?

前端 未结 10 885
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条回答
  •  萌比男神i
    2020-12-23 09:25

    In Swift 3:

        let textFont = UIFont(name: "Helvetica Bold", size: 20)!
        let textColor = UIColor(white: 1, alpha: 1)      // White
        let paragraphStyle = NSMutableParagraphStyle()
        paragraphStyle.paragraphSpacing = 20             // Paragraph Spacing
        paragraphStyle.lineSpacing = 40                  // Line Spacing
    
        let textFontAttributes = [
            NSFontAttributeName: textFont,
            NSForegroundColorAttributeName: textColor,
            NSParagraphStyleAttributeName: paragraphStyle
            ] as [String : Any]
    

提交回复
热议问题