import <UIKit/UIKit.h>
@interface NewLabel : UILabel
@end
import “NewLabel.h"
/*
自定义Label设置中间文字绘制的位置,因为左对齐可以通过加空格控制文字相对左边框的距离,但是右对齐在iOS6.0以后加空格已经没用了,所以可以通过如下方法控制文字右边距
*/
@implementation NewLabel
-(instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
}
return self;
}
//方案
-(void)drawTextInRect:(CGRect)rect
{
/*
super drawTextInRect:UIEdgeInsetsInsetRect(<#CGRect rect#>, UIEdgeInsetsMake(<#CGFloat top#>, <#CGFloat left#>, <#CGFloat bottom#>, <#CGFloat right#>))
*/
[super drawTextInRect:UIEdgeInsetsInsetRect(rect, UIEdgeInsetsMake(12, 0, 0, 20))];
}
@end
自定义Label文字绘制区域
最新推荐文章于 2021-05-19 18:30:25 发布