3

While I found how to add indentations to first line (FirstLineHeadIndent) and to the rest of lines (HeadIndent), I cannot find how to add indents to only first two/three lines in order to achieve something like this: long live MS Paint!

PS: This is not a duplicate, because I'm not asking how to indent only first line, as one user suggested.

4

3 Answers 3

5
+50

You need to set your UILabel text as Attributed string in storyboard.

Then you can edit the indentation of each line, and you can also paste any text you've created with text editor and it will keep its indentation as well as other attributes.

You can of course manipulate these attributes programmatically, here is an example:

@IBOutlet weak var label: UILabel! let text = "\tfirst line\n \tsecond line\nthird line\nforth line" let paragraphStyle = NSMutableParagraphStyle() paragraphStyle.tabStops = [NSTextTab(textAlignment: NSTextAlignment.left, location: 15, options: [:])] paragraphStyle.headIndent = 10 label.attributedText = NSAttributedString(string: text, attributes: [NSParagraphStyleAttributeName: paragraphStyle]) 

Here is an example of how to configure it:

enter image description here

Here is how to configure indentation:

enter image description here

Here is the example on the simulator:

enter image description here

Sign up to request clarification or add additional context in comments.

9 Comments

I dont see what is the problem with my answer? please enlighten me. The asker didn't specify the text have to be aligned according to a picture or a check box
what is that if not a space?
Check out my answer
how to control, which lines are indented?
Curser on the line you wish to change, then click on the button I've marked, each line has its own values on the drop down menu
|
4

Using TextKit Framework in ios

CGRect checkBoxFrame = [self.textView convertRect:self.checkView.bounds fromView:self.checkView]; checkBoxFrame.origin.x -= self.textView.textContainerInset.left; checkBoxFrame.origin.y -= self.textView.textContainerInset.top; UIBezierPath *checkBoxPath = [UIBezierPath bezierPathWithOvalInRect:checkBoxFrame]; self.textView.textContainer.exclusionPaths = @[checkBoxPath]; 

It will exclude the image path inside content of TextView

3 Comments

Not a c# solution, but interesting take on the problem. =)
I need a solution for UILabel though.
Disable User Interaction in TextView will get Label. The UILabel is a read-only UITextView. both are similar. see stackoverflow.com/a/6040449/5215474
0

You would need to use the stringattribute property of the UILabel.AttributedText.

its actually of type NSMutableAttributedString so I first casted label.AttributedText to the mutable type then I could manipulate it.

To do this you would use the following:

var mutable = Control.AttributedText as NSMutableAttributedString; UIStringAttributes uiString=new UIStringAttributes(); 

Then you need to set an indent on the first line (Do this the way you already know how to), and then you would set the headIndent of its paragraph style like below.

this is converted from objective-c so might not be perfect:

NSMutableParagraphStyle paragraphStyle = new NSMutableParagraphStyle(); paragraphStyle.headIndent = 14; NSDictionary attributes (){ StyleAttributeName = paragraphStyle; }; mutable.AddAttribute(attributes); Control.attributedText = mutable; 

I believe something like this in combination with your 'FirstLineHeadIndent' code should do the trick.


How to manipulate NSAttributedString

Objective-C second line with indent

4 Comments

this wouldn't work for indenting only first two lines
even if it did, what if I need to indent three lines?
I honestly, don't think you can easily indent any more than two lines without some fairly substancial messing around with attributed strings.
The only other thing I can think of is splitting your text between two labels programatically, so that you can have one label in the position you need it, and the other fully stretched left to right.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.