Uilabel
UILabel
Text alignment
Margin Padding
Extension
Multi line
This is the normal way of adding multiple lines. Important thing to remember you need to define your height/width constraints properly in order to have multiple line on a UILabel.
textLabel.lineBreakMode = .byWordWrapping
textLabel.numberOfLines = 0
Now if you have NSAttributedString
define which gets added to the label
var attributedTitle: NSAttributedString = {
let title = NSMutableAttributedString(
  icon: Icon.flows,
  iconSize: Constants.iconSize,
  iconColor: labelTextColor)
let paragraphStyle = NSMutableParagraphStyle()
let textRange = NSRange(location: 0,
length:title.length)
paragraphStyle.alignment = .center
paragraphStyle.minimumLineHeight = 12
title.addAttribute(.paragraphStyle,
value: paragraphStyle,
range: textRange)
// Setting the attributed text
textLabel.attributedText = attributedTitle
Remember that your minimumLineHeight could also come in picture with multi - line texts. It didn't help me overall but just letting this in the doc.
SO | multiple lines of text uilabel
HWS | formatting-strings-with-nsattributedstring
Caveats with baseline offset being added which could be non-zero, this would prematurely make the label truncated and the number of lines = 0 not being respected for having multi line support.
title.addAttribute(.baselineOffset,
value: 24,
range: NSRange
(location: 0,
length: element.length)
)