如何知道标签最后一行的宽度? [英] How to know the width of last line of label?
本文介绍了如何知道标签最后一行的宽度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的应用中,我有一个标签,该文本来自服务器,因此我不知道其宽度,并且在该标签的末尾应该直接有一个UIImage.
我的问题是:由于标签文本的宽度非静态,我不知道如何放置图像.
更清楚地说,这是设计的快照,应如何设计:
请问有解决这个问题的建议吗?
解决方案
- 设置
UILabel
的文本 - 通过
yourUILabel
.frame.width 获取此 -
像这样在
yourUILabel.frame.width + emptySpace
上设置UIImage
的x坐标var yourUIImageView:UIImageView = UIImageView(frame:CGRectMake(x:PaddingFromLeft + yourUILabel.frame.width + emptySpace,y:yourYCoordinate,width:yourImageWidth,height:yourImageHeight))
UILabel
的宽度In my app I have a label which text came from the server so I don't Know its width, and at the end of this label directly there should be an UIImage.
My problem is: I don't know how to position the image because of the non static width of the label text.
To be more clear, this is a snapshot form the design and how should it be:
Any suggestion to solve this problem please?
解决方案
- Set the text of the
UILabel
- Get the width of this
UILabel
withyourUILabel
.frame.width Set the x coordinate of your
UIImage
atyourUILabel.frame.width + emptySpace
like thisvar yourUIImageView:UIImageView = UIImageView(frame: CGRectMake(x:PaddingFromLeft + yourUILabel.frame.width + emptySpace, y: yourYCoordinate, width: yourImageWidth, height : yourImageHeight))
这篇关于如何知道标签最后一行的宽度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文