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?
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?
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.
NSMutableParagraphStyle
has an attribute called lineSpacing. Try adding this attribute to an attributed string and setting the label's attributedText
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
Try this
label.padding = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
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
© 2022 - 2024 — McMap. All rights reserved.