Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/106.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 使用NSMutableAttributeString向UILabel添加填充_Ios_Objective C_Uikit_Uilabel - Fatal编程技术网

Ios 使用NSMutableAttributeString向UILabel添加填充

Ios 使用NSMutableAttributeString向UILabel添加填充,ios,objective-c,uikit,uilabel,Ios,Objective C,Uikit,Uilabel,我想给突出显示的UILabel添加一些填充(参见屏幕截图)。 我尝试过这样子类化UILabel,但没有成功: - (id)initWithFrame:(CGRect)frame{ self = [super initWithFrame:frame]; if (self) { self.edgeInsets = UIEdgeInsetsMake(5, 5, 0, 0); //customize padding here } return self;

我想给突出显示的UILabel添加一些填充(参见屏幕截图)。

我尝试过这样子类化UILabel,但没有成功:

- (id)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.edgeInsets = UIEdgeInsetsMake(5, 5, 0, 0); //customize padding here
    }
    return self;
}

- (void)drawTextInRect:(CGRect)rect {
    [super drawTextInRect:UIEdgeInsetsInsetRect(rect, self.edgeInsets)];
}
创建标签的当前函数:

    paddingLabel  *viewTitleLabel = [[paddingLabel alloc]initWithFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, view.frame.size.height)];

    NSMutableAttributedString *s =
    [[NSMutableAttributedString alloc] initWithString:ticketcode];

    [s addAttribute:NSBackgroundColorAttributeName
              value:[UIColor blackColor]
              range:NSMakeRange(0, s.length)];


    viewTitleLabel.attributedText = s;

添加填充到标签?你的意思是图像前面需要一些空间?更像是四个侧面的插图