您的位置:首页 > 产品设计 > UI/UE

UILabel-文字内边距

2016-06-12 14:06 288 查看
自定义UILabel类myLabel

myLabel.h文件中声明一个新的init方法:

- (instancetype)initWithFrame:(CGRect)frame insets:(UIEdgeInsets)insets;
myLabel.m文件中实现drawTextInRect方法:
@implementation myLabel
{
UIEdgeInsets _insets;
}

- (instancetype)initWithFrame:(CGRect)frame insets:(UIEdgeInsets)insets
{
if (self = [superinitWithFrame:frame]) {
_insets = insets;
}
returnself;
}

- (void)drawTextInRect:(CGRect)rect
{
return [superdrawTextInRect:UIEdgeInsetsInsetRect(rect,_insets)];
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: