gpt4 book ai didi

ios - Swift - UILabel 文本未正确显示

转载 作者:行者123 更新时间:2023-11-29 05:08:57 25 4
gpt4 key购买 nike

我不知道为什么我的 UILabel 没有正确显示,而是 Swift 缩短了它,如下图所示:

enter image description here

这就是我创建标签和两条的方式:

let oderLabel: UILabel = {
let v = UILabel()
v.translatesAutoresizingMaskIntoConstraints = false
v.font = UIFont(name: "AvenirNext-DemiBold", size: 15)
v.textColor = .white
v.textAlignment = .center
v.text = "ODER"
return v
}()

let lineLeft: UIImageView = {
let v = UIImageView()
v.translatesAutoresizingMaskIntoConstraints = false
v.image = UIImage(named: "line")
return v
}()

let lineRight: UIImageView = {
let v = UIImageView()
v.translatesAutoresizingMaskIntoConstraints = false
v.image = UIImage(named: "line")
return v
}()

还有我的约束:

    oderLabel.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
oderLabel.bottomAnchor.constraint(equalTo: weiterButton.bottomAnchor, constant: 40).isActive = true

lineLeft.centerYAnchor.constraint(equalTo: oderLabel.centerYAnchor).isActive = true
lineLeft.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 30).isActive = true
lineLeft.trailingAnchor.constraint(equalTo: oderLabel.leadingAnchor).isActive = true

lineRight.centerYAnchor.constraint(equalTo: oderLabel.centerYAnchor).isActive = true
lineRight.leadingAnchor.constraint(equalTo: oderLabel.trailingAnchor).isActive = true
lineRight.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -30).isActive = true

我想要的只是将标签居中,并让两条线旁边有一点空间。并且应该可以在所有尺寸的 iPhone 上正确显示。我现在在这个问题上呆得太久了..

这应该是一个 1 分钟的任务,所以我可能有一些误解。如果有人能在这里帮助我,我将非常感激:)

最佳答案

向 oderLabel 添加适当大小的宽度 anchor 可能会成功。

关于ios - Swift - UILabel 文本未正确显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59866229/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com