gpt4 book ai didi

ios - NSTextAttachment紧缩

转载 作者:行者123 更新时间:2023-12-01 16:38:19 25 4
gpt4 key购买 nike

我正在尝试更改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);

关于ios - NSTextAttachment紧缩,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26373780/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com