Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting UILabel to produce an ellipsis rather than shrinking the font

When I dynamically change the text of a UILabel I would prefer to get an ellipsis (dot, dot, dot) rather then have the text be automatically resized. How does one do this?

In other words, if I have UILabel with the word Cat with size font 14 and then I change the word to Hippopotamus the font shrinks to fit all the word. I would rather the word be automatically truncated followed by an ellipsis.

I assume there is a parameter that can be changed within my UILabel object. I'd rather not do this programmatically.

like image 378
Eric Brotto Avatar asked Oct 11 '11 12:10

Eric Brotto


People also ask

What is UILabel in swift?

A view that displays one or more lines of informational text.

How do I change my UILabel text?

To change the font or the size of a UILabel in a Storyboard or . XIB file, open it in the interface builder. Select the label and then open up the Attribute Inspector (CMD + Option + 5). Select the button on the font box and then you can change your text size or font.


1 Answers

Set the following properties:

Objective C

label.adjustsFontSizeToFitWidth = NO; label.lineBreakMode = NSLineBreakByTruncatingTail; 

Swift

label.adjustsFontSizeToFitWidth = false label.lineBreakMode = .byTruncatingTail 

You can also set these properties in interface builder.

like image 145
jbat100 Avatar answered Nov 08 '22 09:11

jbat100