Skip to content

Instantly share code, notes, and snippets.

@priore
Created April 18, 2016 16:24
Show Gist options
  • Select an option

  • Save priore/18fa84ba000f84a0aaa144afe6e2d933 to your computer and use it in GitHub Desktop.

Select an option

Save priore/18fa84ba000f84a0aaa144afe6e2d933 to your computer and use it in GitHub Desktop.
UILabel correct way to padding left/right
// 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