Created
May 7, 2013 20:21
-
-
Save ShadoFlameX/5535784 to your computer and use it in GitHub Desktop.
UILabel subclass supporting content edge insets via UIEdgeInsets property.
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
// | |
// BHInsetLabel.h | |
// Created by Bryan Hansen on 5/7/13. | |
// | |
#import <UIKit/UIKit.h> | |
@interface BHInsetLabel : UILabel | |
@property (nonatomic, assign) UIEdgeInsets contentInsets; | |
@end | |
@implementation BHInsetLabel | |
#pragma mark - Layout | |
- (CGSize)sizeThatFits:(CGSize)size | |
{ | |
CGSize adjustedSize = [super sizeThatFits:size]; | |
adjustedSize.width += self.contentInsets.left + self.contentInsets.right; | |
adjustedSize.height += self.contentInsets.top + self.contentInsets.bottom; | |
return adjustedSize; | |
} | |
- (void)drawTextInRect:(CGRect)rect | |
{ | |
CGRect insetRect = CGRectMake(self.contentInsets.left, | |
self.contentInsets.top, | |
rect.size.width - self.contentInsets.left - self.contentInsets.right, | |
rect.size.height - self.contentInsets.top - self.contentInsets.bottom); | |
[super drawTextInRect:insetRect]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment