代码之家  ›  专栏  ›  技术社区  ›  Thalatta

使用上下尾随和前导时,将uilabel中的文本与标签顶部对齐

  •  1
  • Thalatta  · 技术社区  · 8 年前

    UIView UILabel . 我已经阅读了以下关于将文本与视图顶部对齐的帖子: Vertically align text to top within a UILabel . 我在这里看到了在不同方法中讨论的方法,但我有一个特例:我不想要 在我的例子中,要通过 UIView视图 从现在起,它被固定到所有四个方向(尾随、前导、顶部和底部)。这是不可能实现的吗?

    1 回复  |  直到 8 年前
        1
  •  2
  •   Shades    8 年前

    您只需约束superview的底部空间(本例中为UIView)大于或等于0。标签的行数为0。


    enter image description here

    enter image description here



    将您的问题作为文本:

     @IBOutlet weak var text: UILabel!
    
         override func viewDidLoad() {
             super.viewDidLoad()
    
             text.text = "I have UIView which has a child UILabel. I have read the following SO post about aligning the text to the top of
     the view : Vertically align text to top within a UILabel. I see the
     approach discussed here in different methodologies"
         }
    

    你得到

    enter image description here

    当标签到达UIView底部时,文本停止。