NSAttributedString ignores Autoshrink and numberOfLines for UILabel (iOS 6)

后端 未结 3 1596
臣服心动
臣服心动 2021-01-31 09:01

I have UILabel with number of lines = 2 system font size = 15 minimum font size = 8 Line break mode - Truncate tail

When I set long text which have type NSString for UI

3条回答
  •  不要未来只要你来
    2021-01-31 09:10

    I found a way to do this:

    label.adjustsFontSizeToFitWidth = true
    label.attributedText = attributedString
    label.lineBreakMode = .ByTruncatingTail // this did the trick!
    

    It only works if the third line is set after setting the attributed string. It seems like the attributed string overrides line break behavior when set (among other things).

提交回复
热议问题