Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement