美文网首页
EdgeInsetsLabel

EdgeInsetsLabel

作者: liboxiang | 来源:发表于2018-05-30 22:41 被阅读6次
    #import <UIKit/UIKit.h>
    
    @interface EdgeInsetsLabel : UILabel
    
    @property(nonatomic, assign) UIEdgeInsets edgeInsets;
    
    @end
    
    #import "EdgeInsetsLabel.h"
    
    @implementation EdgeInsetsLabel
    
    - (CGRect)textRectForBounds:(CGRect)bounds limitedToNumberOfLines:(NSInteger)numberOfLines {
        UIEdgeInsets insets = self.edgeInsets;
        CGRect rect = [super textRectForBounds:UIEdgeInsetsInsetRect(bounds, insets)
                        limitedToNumberOfLines:numberOfLines];
        
        rect.origin.x    -= insets.left;
        rect.origin.y    -= insets.top;
        rect.size.width  += (insets.left + insets.right);
        rect.size.height += (insets.top + insets.bottom);
        
        return rect;
    }
    
    - (void)drawTextInRect:(CGRect)rect {
        [super drawTextInRect:UIEdgeInsetsInsetRect(rect, self.edgeInsets)];
    }
    
    @end
    

    相关文章

      网友评论

          本文标题:EdgeInsetsLabel

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