Last active
March 10, 2017 05:24
-
-
Save akhenakh/e592292ff5a3d7d38c18 to your computer and use it in GitHub Desktop.
Use this Label to have a padding. Place a UILabel in Interface Builder, just change the class to DMBorderLabel then you can set all paddings from Interface Builder https://drive.google.com/uc?id=0B4clDbhSrtODdG9nOF9tTGNRYWs
This file contains hidden or 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
#import <UIKit/UIKit.h> | |
IB_DESIGNABLE | |
@interface DMBorderLabel : UILabel | |
@property (nonatomic) IBInspectable CGFloat topInset; | |
@property (nonatomic) IBInspectable CGFloat bottomInset; | |
@property (nonatomic) IBInspectable CGFloat leftInset; | |
@property (nonatomic) IBInspectable CGFloat rightInset; | |
@end |
This file contains hidden or 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
#import "DMBorderLabel.h" | |
@implementation DMBorderLabel | |
- (void)drawTextInRect:(CGRect)rect { | |
UIEdgeInsets insets = {self.topInset, self.leftInset, self.bottomInset, self.rightInset}; | |
return [super drawTextInRect:UIEdgeInsetsInsetRect(rect, insets)]; | |
} | |
- (CGSize) intrinsicContentSize { | |
CGSize superSize = [super intrinsicContentSize] ; | |
superSize.height += self.topInset + self.bottomInset; | |
superSize.width += self.leftInset + self.rightInset; | |
return superSize ; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment