Created
April 18, 2016 16:24
-
-
Save priore/18fa84ba000f84a0aaa144afe6e2d933 to your computer and use it in GitHub Desktop.
UILabel correct way to padding left/right
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
| // UILabel correct way to padding left/right | |
| #import <UIKit/UIKit.h> | |
| @interface CustomLabel : UILabel | |
| @property (nonatomic, assign) UIEdgeInsets edgeInsets; | |
| @end | |
| #import "CustomLabel.h" | |
| @implementation CustomLabel | |
| - (instancetype)initWithCoder:(NSCoder *)aDecoder | |
| { | |
| if (self = [super initWithCoder:aDecoder]) | |
| { | |
| self.edgeInsets = UIEdgeInsetsZero; | |
| } | |
| return self; | |
| } | |
| - (CGSize)intrinsicContentSize | |
| { | |
| CGSize size = [super intrinsicContentSize]; | |
| size.width += self.edgeInsets.left + self.edgeInsets.right; | |
| return size; | |
| } | |
| - (void)drawTextInRect:(CGRect)rect | |
| { | |
| [super drawTextInRect:UIEdgeInsetsInsetRect(rect, self.edgeInsets)]; | |
| } | |
| @end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment