如何知道标签最后一行的宽度? [英] How to know the width of last line of label?

查看:45
本文介绍了如何知道标签最后一行的宽度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用中,我有一个标签,该文本来自服务器,因此我不知道其宽度,并且在该标签的末尾应该直接有一个UIImage.

我的问题是:由于标签文本的宽度非静态,我不知道如何放置图像.

更清楚地说,这是设计的快照,应如何设计:

请问有解决这个问题的建议吗?

解决方案

  1. 设置 UILabel
  2. 的文本
  3. 通过 yourUILabel .frame.width
  4. 获取此 UILabel 的宽度
  5. 像这样在 yourUILabel.frame.width + emptySpace 上设置 UIImage 的x坐标

      var yourUIImageView:UIImageView = UIImageView(frame:CGRectMake(x:PaddingFromLeft + yourUILabel.frame.width + emptySpace,y:yourYCoordinate,width:yourImageWidth,height:yourImageHeight)) 

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?

解决方案

  1. Set the text of the UILabel
  2. Get the width of this UILabel with yourUILabel.frame.width
  3. Set the x coordinate of your UIImage at yourUILabel.frame.width + emptySpace like this

    var yourUIImageView:UIImageView = UIImageView(frame: CGRectMake(x:PaddingFromLeft + yourUILabel.frame.width + emptySpace, y: yourYCoordinate, width: yourImageWidth, height : yourImageHeight))
    

这篇关于如何知道标签最后一行的宽度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆