首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NSTextAttachment字距调整

NSTextAttachment字距调整
EN

Stack Overflow用户
提问于 2014-10-15 11:00:12
回答 1查看 399关注 0票数 2

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

代码语言:javascript
复制
[attributedString setAttributes:@{NSKernAttributeName:@(1.5)} range:NSMakeRange(0, 1)];

这只会让附件消失,同时给我适当的字距调整空间。我还尝试更改原点的x坐标

代码语言:javascript
复制
- (CGRect)attachmentBoundsForTextContainer:(NSTextContainer *)textContainer proposedLineFragment:(CGRect)lineFrag glyphPosition:(CGPoint)position characterIndex:(NSUInteger)charIndex

这对附件的水平位置没有影响。请给我建议。

EN

回答 1

Stack Overflow用户

发布于 2016-06-30 19:11:27

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

代码语言:javascript
复制
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);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26373780

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档