【问题标题】:NSTextAttachment KerningNSTextAttachment 字距调整
【发布时间】:2014-10-15 03:00:11
【问题描述】:

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

这对附件的水平位置没有影响。 请指教。

【问题讨论】:

    标签: ios uitextview textkit kerning nstextattachment


    【解决方案1】:

    您可以通过 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);
    

    【讨论】:

    • 调整垂直位置。
    猜你喜欢
    • 2017-05-20
    • 2017-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-07
    • 1970-01-01
    • 2012-12-08
    相关资源
    最近更新 更多