Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to increase space between text and its underline within UILabel?

I have a one-line UILabel with attributed string that has underline. Anybody know how to increase space between that text and its underline? I would think this is supposed to be a common thing to do, but I can't find an answer anywhere.

Thanks!

like image 956
ymotov Avatar asked Apr 22 '14 21:04

ymotov


People also ask

How do you increase line spacing in UILabel?

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.. Please see the up to date answers provided below.

How do you underline text in UILabel?

To make the text on UILabel underlined we will need to use the NSMutableAttributedString together with NSUnderlineStyleAttributeName. The Swift code snippet below demonstrates how to create a new UILabel programmatically and then use the NSMutableAttributedString to underline the text on the label.

How do you break a line in UILabel?

To add line breaks in the text we'll use \n character in the string we want to assign to the label. Add the following code to the viewDidLoad Method of your controller class.


1 Answers

I don't think you can, but you're welcome to create an UILabel subclass and drawing your own line (using UIBezierPath or CGPath, for example) at the distance of your choice using the drawRect: method on your subclass.

like image 94
J2theC Avatar answered Oct 13 '22 01:10

J2theC