gpt4 book ai didi

ios - NSTextAttachment 的水平间距

转载 作者:可可西里 更新时间:2023-10-31 23:49:38 25 4
gpt4 key购买 nike

我正在尝试使用 NSTextAttachmentUITextField 中显示图像,但我希望图像和文本之间有一些水平空间。但是,当如下所示将 NSKernAttributeName 属性添加到属性字符串时,它会将附件的高度重置为与周围文本相同的高度。

var str = NSMutableAttributedString(attributedString: NSAttributedString(attachment: imageAttachment))
str.addAttribute(NSKernAttributeName, value: 10, range: NSRange(location: 0,length: 1))

还有其他方法可以在图像和文本之间添加水平空间吗?

最佳答案

最直接的方法就是在字符串开头设置几个空格:

NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
[attachment setImage:[UIImage imageNamed:@"dest_poi_content_quotation"]];
NSString *reviewText = [NSString stringWithFormat:@" %@", review.text];
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:reviewText];
NSAttributedString *attrStringWithImage = [NSAttributedString attributedStringWithAttachment:attachment];
[attributedString insertAttributedString:attrStringWithImage atIndex:0];
[self.lblComment setAttributedText:attributedString];

关于ios - NSTextAttachment 的水平间距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30608726/

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