If I were you, I would subclass UILabel
and add UIEdgeInsets
. In your subclass of UILabel
do something like this:
.m file
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self){
//Property in the header file so we can add custom insets per instance of this class
self.edgeInsets = UIEdgeInsetsMake(0, 0, 0, 0);
}
return self;
}
-(void)drawTextInRect:(CGRect)rect
{
[super drawTextInRect:UIEdgeInsetsInsetRect(rect, self.edgeInsets)];
}
/* So that it will also work with auto layout */
-(CGSize)intrinsicContentSize
{
CGSize size = [super intrinsicContentSize];
size.width += self.edgeInsets.left + self.edgeInsets.right;
size.height += self.edgeInsets.top + self.edgeInsets.bottom;
if (self.numberOfLines == 0){
//There is a bug where intrinsice content
//size may be 1 point too short
size.height += 1;
}
return size;
}