Sai Bharath Yadav
Sai Bharath Yadav

Reputation: 252

iOS : UILabel multiple lines - second line of label needs to start with 10 pixels

enter image description here

I am facing one issue that is - I have one label like "1. The Seibl is a software made by the some company and can be purchased at $500"

When it comes to iPhone 4s, the label is printing second line and second line is starting exactly under "1.". I would like to give space/margin/space so that label looks like numbering format.

Upvotes: 1

Views: 387

Answers (2)

Sourabh Sharma
Sourabh Sharma

Reputation: 8322

Try this solution. It might helps you.

Use an NSAttributedString for your label, and set the headIndent of its paragraph style:

NSMutableParagraphStyle *style = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
style.headIndent = 14;
NSDictionary *attributes = @{
    NSParagraphStyleAttributeName: style
};
NSAttributedString *richText = [[NSAttributedString alloc] initWithString:@"So this UILabel walks into a bar…" attributes:attributes];
self.narrowLabel.attributedText = richText;
self.wideLabel.attributedText = richText;

Result:

example result

Upvotes: 5

sschale
sschale

Reputation: 5188

Take a look at using a TextView instead, and modifying its textStorage property to define an exclusion area so that a new line is inset. Here's a link to the documentation.

Upvotes: 1

Related Questions