1

Now, I trying to decrease a spacing between multiple line Label. For my way I create function like this..

func setLineHeight(lineHeight: CGFloat) {
    let paragraphStyle = NSMutableParagraphStyle()
    paragraphStyle.lineSpacing = 1.0
    paragraphStyle.lineHeightMultiple = lineHeight
    paragraphStyle.alignment = self.textAlignment

    let attrString = NSMutableAttributedString()
    if (self.attributedText != nil) {
        attrString.append( self.attributedText!)
    } else {
        attrString.append( NSMutableAttributedString(string: self.text!))
        attrString.addAttribute(NSAttributedString.Key.font, value: self.font, range: NSMakeRange(0, attrString.length))
    }
    attrString.addAttribute(NSAttributedString.Key.paragraphStyle, value:paragraphStyle, range:NSMakeRange(0, attrString.length))
    self.attributedText = attrString
}

and use it by myLabel.setLineHeight(0.7)

For problem, It can decrease a line height ! but...It remain a extra space at the bottom of label.

enter image description here

I align my text to centered vertically to parent view but after I setLineHeight It won't center anymore. Has anyone seen this problem?

For constraint of label v enter image description here

Nawin P.
  • 223
  • 1
  • 4
  • 11

1 Answers1

0

You can set line spacing from storyboard as well and keep the alignment as shown in following gif

enter image description here

abh
  • 1,189
  • 2
  • 14
  • 30
  • thank you for you answer, but I didn't lock any constraint except left, right and vertically in container krub. – Nawin P. Jan 06 '21 at 10:21