版權聲明:本文爲博主原創文章,未經博主允許不得轉載。 https://blog.csdn.net/qq_28125515/article/details/50392836
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