Ios NSTEXT附件紧排

Ios NSTEXT附件紧排,ios,uitextview,textkit,kerning,nstextattachment,Ios,Uitextview,Textkit,Kerning,Nstextattachment,我正在尝试更改UITextView中NSTextAttachment图像的水平位置。我试过了 [attributedString setAttributes:@{NSKernAttributeName:@(1.5)} range:NSMakeRange(0, 1)]; 这只是让附件消失,同时给我适当的紧排空间。我还尝试在中更改原点x坐标 - (CGRect)attachmentBoundsForTextContainer:(NSTextContainer *)textContainer pro

我正在尝试更改UITextView中NSTextAttachment图像的水平位置。我试过了

[attributedString setAttributes:@{NSKernAttributeName:@(1.5)} range:NSMakeRange(0, 1)];
这只是让附件消失,同时给我适当的紧排空间。我还尝试在中更改原点x坐标

- (CGRect)attachmentBoundsForTextContainer:(NSTextContainer *)textContainer proposedLineFragment:(CGRect)lineFrag glyphPosition:(CGPoint)position characterIndex:(NSUInteger)charIndex
这对附件的水平位置没有影响。
请告知

您可以通过textAttachment.bounds属性设置NSTextAttachment图像的水平位置

NSTextAttachment *textAttachment = [[NSTextAttachment alloc] init];
NSURLRequest *imageRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:@"YourImageURL"] cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:60];
NSData *urlData=[NSURLConnection sendSynchronousRequest:imageRequest returningResponse:nil error:nil];
UIImage * image = [UIImage imageWithData:urlData];
if (image != nil) {
textAttachment.image = image;
} else {
textAttachment.image =[UIImage imageNamed:@"YourPlaceHolderImageName"];
            }
textAttachment.bounds =  CGRectMake(0,-4, textAttachment.image.size.height, textAttachment.image.size.width);