Advertisement
priore

UILabel correct way to padding left/right

Apr 18th, 2016
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // UILabel correct way to padding left/right
  2. #import <UIKit/UIKit.h>
  3.  
  4. @interface CustomLabel : UILabel
  5.  
  6. @property (nonatomic, assign) UIEdgeInsets edgeInsets;
  7.  
  8. @end
  9.  
  10. #import "CustomLabel.h"
  11.  
  12. @implementation CustomLabel
  13.  
  14. - (instancetype)initWithCoder:(NSCoder *)aDecoder
  15. {
  16.     if (self = [super initWithCoder:aDecoder])
  17.     {
  18.         self.edgeInsets = UIEdgeInsetsZero;
  19.     }
  20.    
  21.     return self;
  22.    
  23. }
  24.  
  25. - (CGSize)intrinsicContentSize
  26. {
  27.     CGSize size = [super intrinsicContentSize];
  28.     size.width += self.edgeInsets.left + self.edgeInsets.right;
  29.     return size;
  30. }
  31.  
  32. - (void)drawTextInRect:(CGRect)rect
  33. {
  34.     [super drawTextInRect:UIEdgeInsetsInsetRect(rect, self.edgeInsets)];
  35. }
  36.  
  37. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement