你怎么能用uilabel包裹图像(如图所示) [英] How could you make a uilabel wrap around an image (like shown)
本文介绍了你怎么能用uilabel包裹图像(如图所示)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你怎么能达到这个效果:
How could you achieve this effect:
也许某种NSAtributedString?
Maybe some sort of NSAtributedString?
我已经想到了添加空格的hacky方法,但它需要根据图像的宽度动态地进行。
I have thought of hacky ways to just add spaces, but it needs to do it dynamically based on the width of the image.
任何想法?
注意很高兴你可以很容易地做到这一点使用UITextView:
NOTE happily you can do this very easily with UITextView:
https://stackoverflow.com/a/20033752/ 294884
这个问题与UILabel有关。
this question is about UILabel.
推荐答案
在标签中添加图片,文字如下代码:
Add image in your label with text as below code:
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];
您的 OUTPUT :
这篇关于你怎么能用uilabel包裹图像(如图所示)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文