Skip to content

Instantly share code, notes, and snippets.

@akhenakh
Last active March 10, 2017 05:24
Show Gist options
  • Save akhenakh/e592292ff5a3d7d38c18 to your computer and use it in GitHub Desktop.
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
#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
#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