mark jannet
mark jannet

Reputation: 580

UILabel top alignment with multiline

I have a UILabel with 4 lines in a UICollectionView. When there are fewer than 4 rows, I want the text to be on the top and not in the centre.

Thanks..

Upvotes: 4

Views: 7926

Answers (2)

thomasdao
thomasdao

Reputation: 982

In Swift:

yourLabel.lineBreakMode = NSLineBreakMode.ByClipping 
yourLabel.text = yourString.stringByAppendingString("\n\n\n\n")

Upvotes: 1

Mirko Catalano
Mirko Catalano

Reputation: 3850

this is the solution

dispatch_async(dispatch_get_main_queue(), ^{
            yourLabel.numberOfLines = 0;
            [yourLabel sizeToFit];


        });

Upvotes: 4

Related Questions