首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NSTextAttachment的水平间距

NSTextAttachment的水平间距
EN

Stack Overflow用户
提问于 2015-06-03 08:15:46
回答 1查看 2.6K关注 0票数 3

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

代码语言:javascript
复制
var str = NSMutableAttributedString(attributedString: NSAttributedString(attachment: imageAttachment))
str.addAttribute(NSKernAttributeName, value: 10, range: NSRange(location: 0,length: 1))

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

EN

回答 1

Stack Overflow用户

发布于 2015-06-03 11:07:21

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

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

https://stackoverflow.com/questions/30608726

复制
相关文章

相似问题

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