How can I underline a text that could be multiple lines of string? I find some people suggest UIWebView, but it is obviously too heavy a class for just text rendering.
My thoughts was to figure out the start point and length of each string in each line. And draw a line under it accordingly.
I meet problems at how to figure out the length and start point for the string. Can anybody help me on this?
I tried to use -[UILabel textRectForBounds:limitedToNumberOfLines:]
, this should be the drawing bounding rect for the text right?
Then I have to work on the alignment?
How can I get the start point of each line when it is center-justified and right justified?
I am new here, so thank you in advance.
In Swift:
You can create a custom label with name UnderlinedLabel and edit drawRect function.
I use an open source line view and just added it to the button subviews:
This was inspired by Karim above.
People, who do not want to subclass the view (UILabel/UIButton) etc... 'forgetButton' can be replace by any lable too.
Here's another, simpler solution (underline's width is not most accurate but it was good enough for me)
I have a UIView
(_view_underline)
that has White background, height of 1 pixel and I update its width everytime I update the text