How to add padding-left on a UILabel created programmatically?

前端 未结 8 1117
温柔的废话
温柔的废话 2020-12-29 06:33

I know this is a noob question but ...I have these labels on a tableview, but the text is completely squished to the left. I want to add a bit of padding. How do I go about

8条回答
  •  旧巷少年郎
    2020-12-29 07:02

    You can create a subclass of UILabel and override intrinsicContentSize and - (CGSize)sizeThatFits:(CGSize)size:

    - (CGSize) intrinsicContentSize
    {
        CGSize parentSize = [super intrinsicContentSize];
        parentSize.width += 2*PADDING_VALUE;
        return parentSize;
    }
    
    - (CGSize)sizeThatFits:(CGSize)size
    {
        CGSize parentSize = [super sizeThatFits:size];
        parentSize.width += 2*PADDING_VALUE;
        return parentSize;
    }
    

提交回复
热议问题