Core Text - NSAttributedString line height done right?

前端 未结 10 875
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:23

    Another way of twerking with a NSAttributedString line position is playing with baselineOffset attribute:

    let contentText = NSMutableAttributedString(
    string: "I see\nI'd think it`d be both a notification and a\nplace to see past announcements\nLike a one way chat.")
    
    contentText.addAttribute(.baselineOffset, value: 10, range: NSRange(location: 0, length: 5))
    contentText.addAttribute(.baselineOffset, value: -10, range: NSRange(location: 85, length: 20))
    


    Result:

    "I see

    I'd think it`d be both a notification and a
    place to see past announcements

    Like a one way chat."

    https://stackoverflow.com/a/55876401/4683601

提交回复
热议问题