美文网首页
UILabel 设置 text Insets(padding)

UILabel 设置 text Insets(padding)

作者: TyroneLin | 来源:发表于2021-08-04 15:44 被阅读0次
    @interface UALabel : UILabel
    
    @property (nonatomic, assign) UIEdgeInsets insets;
    
    @end
    
    @implementation UALabel
    
    #pragma mark - override
    
    - (void)drawTextInRect:(CGRect)rect {
        [super drawTextInRect:UIEdgeInsetsInsetRect(rect, self.insets)];
    }
    
    - (CGSize)intrinsicContentSize {
        CGSize size = [super intrinsicContentSize];
        size.width += (self.insets.left + self.insets.right);
        size.height += (self.insets.top + self.insets.bottom);
        return size;
    }
    
    #pragma mark - getter && setter
    
    - (void)setInsets:(UIEdgeInsets)insets {
        _insets = insets;
        [self layoutSubviews];
    }
    
    @end
    

    相关文章

      网友评论

          本文标题:UILabel 设置 text Insets(padding)

          本文链接:https://www.haomeiwen.com/subject/ouuuvltx.html