自定義Label文字繪製區域

版權聲明:本文爲博主原創文章,未經博主允許不得轉載。 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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章