Make a subclass of UILabel
.h file
@property (nonatomic, assign) UIControlContentVerticalAlignment verticalAlignment;
.m file
- (void) drawTextInRect:(CGRect)rect
{
if(_verticalAlignment == UIControlContentVerticalAlignmentTop || _verticalAlignment == UIControlContentVerticalAlignmentBottom)
{
// If one line, we can just use the lineHeight, faster than querying sizeThatFits
const CGFloat height = floorf(((self.numberOfLines == 1) ? ceilf(self.font.lineHeight) : [self sizeThatFits:self.frame.size].height));
rect.origin.y = floorf(((self.frame.size.height - height) / 2.0f) * ((_verticalAlignment == UIControlContentVerticalAlignmentTop) ? -1.0f : 1.0f));
}
[super drawTextInRect:rect];
}
- (void) setVerticalAlignment:(UIControlContentVerticalAlignment)newVerticalAlignment
{
_verticalAlignment = newVerticalAlignment;
[self setNeedsDisplay];
}
I used this for Vertical Alignment .