Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Build a Playlist Browser with Swift Building the Master and Detail Views Displaying Playlist Information

Anonymous Person
Anonymous Person
5,297 Points

Multiple lines in a UILabel

How do I get multiple lines within a UILabel through code?

Anon, your post posted six+ times, you might want to delete the extras.

Kristopher Van Sant
Kristopher Van Sant
Courses Plus Student 18,830 Points

Hey there Anonymous! I removed your extra posts. Only one post is needed per question. :)

1 Answer

Michael Hulet
Michael Hulet
47,912 Points

There's actually a property on UILabel to set the number of lines it can use. You can either set it to an explicit number of lines, or you can set it to 0, and it'll use as many as it needs. You can try this:

// Let the label use an unlimited amount of lines
label.numberOfLines = 0
// Resize the label so you can see all the text inside
label.sizeToFit()