ios – 你怎么能用uilabel包裹图像(如图所示)

ios – 你怎么能用uilabel包裹图像(如图所示),第1张

概述你怎么能达到这个效果: 也许是某种NSAtributedString? 我曾想过只添加空格的hacky方法,但它需要根据图像的宽度动态地进行. 有任何想法吗? 请注意,您可以使用UITextView轻松完成此 *** 作: https://stackoverflow.com/a/20033752/294884 这个问题是关于UILabel的. 使用文本在标签中添加图片,如下所示: NSMutableAtt 你怎么能达到这个效果:

也许是某种NSAtributedString?

我曾想过只添加空格的Hacky方法,但它需要根据图像的宽度动态地进行.

有任何想法吗?

请注意,您可以使用UITextVIEw轻松完成此 *** 作:

https://stackoverflow.com/a/20033752/294884

这个问题是关于UILabel的.

解决方法 使用文本在标签中添加图片,如下所示:
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:@"Here is some text that is wrapPing around like an image"];    NSTextAttachment *textAttachment = [[NSTextAttachment alloc] init];    textAttachment.image = [UIImage imagenamed:@"first.jpg"];    NSAttributedString *attrStringWithImage = [NSAttributedString attributedStringWithAttachment:textAttachment];    [attributedString insertAttributedString:attrStringWithImage atIndex:0];    [_lbn setAttributedText:attributedString];

你的输出:

总结

以上是内存溢出为你收集整理的ios – 你怎么能用uilabel包裹图像(如图所示)全部内容,希望文章能够帮你解决ios – 你怎么能用uilabel包裹图像(如图所示)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1105626.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存