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