How to draw a non-rectangle UILabel with paragraph truncation at the end? - ios

I need to show a body of text similar to the one shown below and limited to the red non-rectangular area. Rob's answer to this question pretty much answers my question as well, but I also need to truncate at tail of the paragraph when the text is too long.
Extra question: is it also possible to set minimum font size similar to UILabel?

Try using NSString::sizeWithFont:constrainedToSize method which is documented here. You can specify the fontsize and maximum size for the text.
You can also calculate the minimum font size using NSString::sizeWithFont:minFontSize:actualFontSize:forWidth:lineBreakMode: method.

Related

Add custom space to UILabel

I've a weird problem that faces me. I've a UILabel contains text of multiple lines and I'm using bullet in the first line "•".
But my problem is that the second line is not aligned with first character after the bullet.
I measured it and found that width of the bullet is a little bit bigger tan width of normal space.
Is there any trick for that?
the issue is concerning font attributes. Get into the difference of monospaced fonts and proportional fonts, then you will know why there's a difference between space and bullet in your font
https://en.wikipedia.org/wiki/Monospaced_font
easy solution and maybe really an option for you is to use a monospaced font.
Okay, I found a powerful answer by using NSParagraphStyle.
https://wingoodharry.wordpress.com/2016/04/10/bullet-point-list-ios-swift/

UILabel divides single word

Good day folks,
Actually I'm going crazy, I did everything I could in order to solve this simple problem.
As you see, a simple label in a narrow space causes the single word "Verification" to be separated into two lines which is not acceptable of course.
I know that I could make number of lines only 1 and this will decrease font size, I tried all wraps modules and all fails.
What can I do to display the label as "Verification Process" without any separation of a single word? (I accept even shrinking font size or clipping last word).
The first one is default setting
Does these two settings below meet your needs?
If you are ok with clipping of the words, then you can set the lines property of your label to 1. Or you want to reduce the font size that also can be done using storyboard property inspector. Hope this will help.
please try this.
my testLabel and number of lines equal to 2.
self.testLabel.lineBreakMode = NSLineBreakByWordWrapping;
self.testLabel.text = #"verificaton process";

How to adjust Font Size according text viewable in a TButton.Text using Firemonkey?

I am using buttons to display product names in a matrix using TGridLayout.
The problem is that commonly Items contains 3 or 4 words and in my language (Portuguese) some words tend to be long.
I would like that somehow I could calculate the size of the font, decreasing it, in order to make all the text show up automatically (of course there is also a decrease limit, anything below 9 or 8 point for the font turn to be difficult to read).
The wordwrap property is turned on to have many lines, and use the most possible space for the text.
I don't know if you're programming for an Android/iOS app, but you can't change the fontsize of a button. I've had the same problem, my solution was to make an abbreviation of the words. And then i put labels above it to explain the abbreviations.
Of course you can adjust the font size of a button:
TButton.TextSettings.Font.Size

Line fill for UITextView?

Is there a property that will apply the proper character spacing to have all the text on each line in an NSAttributedString butt up against the bounds like in a book, (including the final line which I know isn't done in books)? I know kerning can be adjusted, but that won't dynamically adjust on a per line basis. Any help would be appreciated. Also NSTextAlignmentJustified and NSTextAlignmentNatural get close, but won't apply the effect to the last line of text.
The only option is to use NSTextAlignmentJustified. Last line is never justified, because NSTextAlignmentJustified refers to Left Justification mode, as it is the standard case.
For more information you can take a look at Typographic Alignment on wikipedia : http://en.wikipedia.org/wiki/Typographic_alignment

Means to get detailed font metrics?

I'm puzzling how to divine more font metrics from iOS. I can accomplish my very long single line of text by paging UIViews while scrolling. I can determine where to break the strings between views by iteratively calculating it with sizeToFont, but I need the inter-character spacing (i.e. advance width) to space them accurately.
Any ideas short of full fixed or monospaced fonts? Thanks.
The Core Text class CTFont gives you some access to glyph metrics. But really, you should try to just use Core Text to do your text rendering instead of asking it for measurements and calculating positions yourself.
CTFont Reference
Core Text Programming Guide

Resources