IOS UILabel long string processing

= NSLineBreakMode.byTruncatingMiddle label.lineBreakMode
label.numberOfLines // default = 0 means no limitation is 1,0
label.adjustsFontSizeToFitWidth = true // font size adaptive
label.allowsDefaultTighteningForTruncation = true // reduced word spacing

// the passed string font maximum width and height, actually occupied return string width and height
class FUNC getTextRectSize (text: NSString, font: UIFont, size: CGSize) -> {the CGRect
the let Attributes = [ NSFontAttributeName: font]
the let Option = NSStringDrawingOptions.usesLineFragmentOrigin
the let RECT: the CGRect = text.boundingRect (with: size, Options: Option, Attributes: Attributes, context: nil)
Print ( "RECT: (RECT)");
return RECT;
}

NSLineBreakMode enumeration:


9967595-788ffefd7fa5c128.png
image.png

Guess you like

Origin blog.csdn.net/weixin_34240657/article/details/90866438