8

If it were a TextView I could do

self.textView.textContainer.lineFragmentPadding = 0;

But what I have is a multiline label. How do I remove the padding?

Katedral Pillon
  • 14,984
  • 21
  • 92
  • 196

4 Answers4

2

If you're using iOS 8, try changing the insets value of layoutMargins property. If it doesn't work or you're targeting earlier versions, look at this answer.

Community
  • 1
  • 1
Mercurial
  • 1,955
  • 3
  • 17
  • 29
1

NSMutableParagraphStyle has an attribute called lineSpacing. Try adding this attribute to an attributed string and setting the label's attributedText

Roderic Campbell
  • 719
  • 5
  • 14
1

you can try this:

        let attributedString: NSMutableAttributedString = NSMutableAttributedString(string: str)
        let paragraphStyle: NSMutableParagraphStyle = NSMutableParagraphStyle()
        paragraphStyle.lineHeightMultiple = 0.75 //or other values you like
        attributedString.addAttribute(NSAttributedString.Key.paragraphStyle, value: paragraphStyle, range: NSMakeRange(0, str.count))
        typeLabel.attributedText = attributedString
litwill
  • 11
  • 1
-3

I recommend to change your UILabel into UITextView and put this code.

yourTextView.textContainerInset = UIEdgeInsetsMake(0,0,0,0);

don't forget to set yourTextView

yourTextView.editable = NO
yourTextView.scrollEnabled = NO