如何在NSAttributedString中控制图像和文本之间的填充?

时间:2017-11-24 08:21:52

标签: ios nsattributedstring

我使用NSTextAttachment在NSAttributedString中嵌入图像。但是我发现图像(PK图标)对文本是如此封闭,如果我想在它们之间做一些距离,如何实现这一点。

enter image description here

NSMutableAttributedString* attri = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@" %@",item.title]];
if (item.isPK)
{
    NSTextAttachment *imageAtta = [[NSTextAttachment alloc] init];
    imageAtta.bounds = CGRectMake(0, 0, 27, 13);
    imageAtta.image = [UIImage imageNamed:@"PKIcon"];
    NSAttributedString *attach = [NSAttributedString attributedStringWithAttachment:imageAtta];
    [attri insertAttributedString:attach atIndex:0];
}

self.titleLabel.attributedText = attri;

0 个答案:

没有答案