Top aligned UILabel, make text stick to top of label view -ios

Viewed 48417

Is there a way to "top align" a UILabel, that is make text stick to top of label view? As opposed to center aligned vertically, or float in the center of the view, as is the default?

Here is an image of three labels, aligned left, right and center, and a UITextView that is aligned center and top. The text of the textView sticks to the top regardless of the vertical size of the view. Can I do the same thing with a label?

enter image description here

8 Answers

What I did in my app was to set the UILabel's line property to 0 as well as to create a bottom constraint of the UILabel and make sure it is being set to >= 0 as shown in the image below.

enter image description here

My problem was in collectionviewCell, I wanted my label to contain text I set to be top align, so I found a way to get it done is I took a uiview first which I set to height and width of contentview of collectionview then I added my imageview and label to the UIView. I set height and width of imageview and for label I just gave trailing, leading and top.

My collectionview

Related