I want to add an image in start of UILabel. Label is multiline. If I use contentInset, it indent the whole label but I want to indent first line only.
I have tried this so far, this doesn't work for me.
UIEdgeInsets titleInsets = UIEdgeInsetsMake(0.0, 40.0, 0.0, 0.0);
valueLabel.contentInset = titleInsets;
It should look like this.
"Short answer: you can't. To change the spacing between lines of text, you will have to subclass UILabel and roll your own drawTextInRect, or create multiple labels." This is a really old answer, and other have already addded the new and better way to handle this..
Changing the text of an existing UILabel can be done by accessing and modifying the text property of the UILabel . This can be done directly using String literals or indirectly using variables.
label. A non-editable text control. The component is used to display static text on a page.
Label is a user interface item in SwiftUI which enables you to display a combination of an image (icon, SF Symbol or other) and a text label in a single UI element.
Here's how you can do this in Interface Builder:
@DavidCaunt suggestion worked for me. I am sharing code here.
NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
style.firstLineHeadIndent = 50;
[attributedText addAttribute:NSParagraphStyleAttributeName value:style range:range];
[valueLabel setAttributedText:attributedText];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With