UILabel don't show all text

Viewed 2270

I'm trying to create an iOS application that would be a quiz but I have a problem with the display. Here is what happens by testing:

Example of one question of the quiz

Example of one question of the quiz

But the question is not displayed entirely. The question is : "En France, depuis les débuts de la Ve République, combien y a-t-il eu de présidents différents élus ?"

I show you the UILabel infos :

UILabel informations

Can you help me please ?

Thanks a lot for your help :) !

4 Answers

For your text inside the label to wrap , plus adding top && centerX constraints , you need to add a width constraint , so either

top , centerX , width

OR

top , leading , trailing

Also you may set bottom of it to any component that below it

Just follow the code below.

// Swift
textLabel.lineBreakMode = .ByWordWrapping // or NSLineBreakMode.ByWordWrapping
textLabel.numberOfLines = 0 

// For Swift >= 3
textLabel.lineBreakMode = .byWordWrapping // notice the 'b' instead of 'B'
textLabel.numberOfLines = 0

// Objective-C
textLabel.lineBreakMode = NSLineBreakByWordWrapping;
textLabel.numberOfLines = 0;

// C# (Xamarin.iOS)
textLabel.LineBreakMode = UILineBreakMode.WordWrap;
textLabel.Lines = 0;  

On the attributes inspector you can just updates the lines property to be 0. In this way you won't have to do it in code.

if you are using autolayout in storybaord you can just remove width from constariants and when you will provide text in it will automatically adjust its width and your label will show all data or you can set minimum font size in storyboard then it will automatically font will set according to your label width and will show complete label data your just need to pass minimum font size.

Related