如何在NSAttributedString中设置边距(填充)?

时间:2015-05-13 16:51:06

标签: ios objective-c uitextview nsattributedstring

我使用NSAttributedString将图像插入到UITextView中,但问题是我想将顶部填充设置为几个点(2/3),以便图像y中心位于{{3文本。

这是我的代码:

        NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:currentMessage];
NSTextAttachment *textAttachment = [[NSTextAttachment alloc] init];
        textAttachment.image = [UIImage imageWithCGImage:[[imagesArray objectAtIndex:count] CGImage] scale:4.0 orientation:UIImageOrientationUp];
        NSAttributedString *attrStringWithImage = [NSAttributedString attributedStringWithAttachment:textAttachment];

        int newPos = [[imagesPosArray objectAtIndex:count] intValue];
        [attributedString replaceCharactersInRange:NSMakeRange(newPos, 1) withAttributedString:attrStringWithImage];
        messageTextView.attributedText = attributedString;

0 个答案:

没有答案