9

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,534
  • 25
  • 99
  • 199

5 Answers5

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
  • 2,095
  • 4
  • 19
  • 33
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(string: str)
let paragraphStyle = 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
Olcay Ertaş
  • 5,987
  • 8
  • 76
  • 112
litwill
  • 11
  • 1
-1

Try this

label.padding = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
miss Most
  • 1
  • 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