要更改 Label 距离边框的距离就需要自定义 Label,完了重写该方法
/* 距离左5个单位,距离上5个单位*/
-(void)drawTextInRect:(CGRect)rect{
CGRect frame = CGRectMake(rect.origin.x + 5, rect.origin.y + 5, rect.size.width - 10, rect.size.height -10);
[super drawTextInRect:frame];
}
本文介绍如何在iOS开发中自定义UILabel以改变其文本相对于边框的位置。通过重写drawTextInRect方法,实现文本距离左5个单位、上5个单位的效果。
要更改 Label 距离边框的距离就需要自定义 Label,完了重写该方法
/* 距离左5个单位,距离上5个单位*/
-(void)drawTextInRect:(CGRect)rect{
CGRect frame = CGRectMake(rect.origin.x + 5, rect.origin.y + 5, rect.size.width - 10, rect.size.height -10);
[super drawTextInRect:frame];
}
2万+
3513
7684
1214
1万+

被折叠的 条评论
为什么被折叠?
