Created
April 8, 2013 11:37
-
-
Save maxhuk/5336182 to your computer and use it in GitHub Desktop.
A simple way to adjust the size of an UILabel to fit its contents by changing height only. Supports attributed strings.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// UILabel+SizeToFit.h | |
// | |
// Created by Maksym Huk on 4/4/13. | |
// Copyright (c) 2013 Maksym Huk. All rights reserved. | |
// | |
#import <UIKit/UIKit.h> | |
@interface UILabel (SizeToFit) | |
- (void)sizeToFitByChangingHeight; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// UILabel+SizeToFit.m | |
// | |
// Created by Maksym Huk on 4/4/13. | |
// Copyright (c) 2013 Maksym Huk. All rights reserved. | |
// | |
#import "UILabel+SizeToFit.h" | |
@implementation UILabel (SizeToFit) | |
- (void)sizeToFitByChangingHeight | |
{ | |
CGRect frame = self.frame; | |
CGSize size = [self sizeThatFits:CGSizeMake(frame.size.width, CGFLOAT_MAX)]; | |
frame.size.height = size.height; | |
self.frame = frame; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment