How do I add padding to a UILabel
while positioning and sizing it with Auto Layout?
I tried subclassing it and overriding the drawTextInRect:
method like this:
- (void)drawTextInRect:(CGRect)rect {
CGFloat borderWidth = 5;
CGFloat doubleBigSquareRadius = CGRectGetWidth(rect);
CGFloat doubleSmallSquareRadius = doubleBigSquareRadius - borderWidth * 2;
CGFloat smallSquareSideSize = doubleSmallSquareRadius / sqrt(2);
CGFloat smallSquareOffset = (doubleBigSquareRadius - smallSquareSideSize) / 2;
CGSize smallSquareSize = CGSizeMake(smallSquareSideSize, smallSquareSideSize);
CGPoint smallSquareOrigin = CGPointMake(smallSquareOffset, smallSquareOffset);
CGRect smallSquareFrame = CGRectMake(smallSquareOrigin.x, smallSquareOrigin.y, smallSquareSize.width, smallSquareSize.height);
[super drawTextInRect:smallSquareFrame];
}
but it doesn't get called at all.