关于iOS UILabel 设置 UIEdgeInsets

来源:互联网 发布:mysql执行计划在哪看 编辑:程序博客网 时间:2024/05/16 10:31

直接上代码
.h

#import <UIKit/UIKit.h>@interface LabelInSet : UILabel@property (nonatomic, assign) UIEdgeInsets insets;@end

.m

#import "LabelInSet.h"@implementation LabelInSet/** *  重写initWithFrame *  @param frame frame *  @return LabelInSet */- (id)initWithFrame:(CGRect)frame {    self = [super initWithFrame:frame];    if (self) {        self.insets = UIEdgeInsetsMake(0.0f, 0.0f, 0.0f, 0.0f);    }    return self;}/** *  重写drawTextInRect,根据insets绘制Label *  @param rect CGRect */- (void)drawTextInRect:(CGRect)rect {    UIEdgeInsets insets = _insets;    [super drawTextInRect:UIEdgeInsetsInsetRect(rect, insets)];}@end
0 0
原创粉丝点击