How the UILabel
can be aligned from bottom. Let say, my label can hold three line of text.If the input text is single line, then this line should come bottom of the
I had the same issue. Here is how I made to align the text to the bottom of my UILabel:
- (void)alignLabel:(UILabel *)l withText:(NSString *)text verticalAlignOption:(int)vertAlign{
CGSize stringSize = [text sizeWithFont:l.font constrainedToSize:l.frame.size lineBreakMode:l.lineBreakMode];
switch (vertAlign) {
case 0: // align = top
l.frame = CGRectMake(l.frame.origin.x,
l.frame.origin.y,
l.frame.size.width,
stringSize.height
);
break;
case 1: // align = bottom
l.frame = CGRectMake(l.frame.origin.x,
(l.frame.origin.y + l.frame.size.height) - stringSize.height,
l.frame.size.width,
stringSize.height
);
break;
case 2: // align = middle
// default
break;
}
l.text = text;
}
Ahd you simple call the method like this to align to the bottom:
[self alignLabel:self.mediaTitle withText:@"My text to align" verticalAlignOption:1];