Reputation: 11399
I have a label that I create using the following way:
UILabel *label = [[UILabel alloc] initWithFrame:cell.contentView.bounds];
label.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
label.textAlignment = UITextAlignmentCenter;
I would like to center the on the bottom of the label and center it horizontally. I did not find any UITextAlignmentBottom in the typedef enums.
Can somebody suggest a solution?
Upvotes: 0
Views: 305
Reputation: 1011
I'm not entirely sure what you mean by "center the on the bottom of the label", but I'm thinking you might be asking about how to center a label at the bottom of the view controller that it's in. To do this, you will want to add some NSLayoutConstraint
s to specify where in the window you want the label to go.
To do this programmatically, you will use constraintWithItem:attribute:relatedBy:toItem:attribute:multiplier:constant:
. The "attribute" argument refers to NSLayoutAttribute
, which can be set as NSLayoutAttributeCenterX
when attempting to center the label, and NSLayoutAttributeBottom
to specify the amount of space between the label and the bottom of the view controller.
Upvotes: 0
Reputation: 25697
To 'align' the text to the bottom, you will want to make the UILabel the height of the text it needs to display - Google UILabel sizeToFit
.
Upvotes: 1