Skip to content

Instantly share code, notes, and snippets.

@ehuynh
Created February 29, 2012 02:01
Show Gist options
  • Save ehuynh/1936946 to your computer and use it in GitHub Desktop.
Save ehuynh/1936946 to your computer and use it in GitHub Desktop.
Resizes the height of a UILabel so that the contain appears vertically align.
#import <UIKit/UIKit.h>
@interface UILabel (VerticalAlign)
- (void)alignTop;
@end
#import "UILabel+VerticalAlign.h"
@implementation UILabel (VerticalAlign)
- (void)alignTop
{
CGSize descriptionSize = [self.text sizeWithFont:self.font
constrainedToSize:self.frame.size
lineBreakMode:self.lineBreakMode];
self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y, self.frame.size.width, descriptionSize.height);
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment