ios - Swift - UILabel 文本未正确显示
问题描述
我不知道为什么我UILabel
的显示不正确,而是 Swift 缩短了它,如下图所示:
这就是我创建label
和两者的方式lines
:
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
}()
我的constraints
:
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
我想要的只是将label
两者居中并在其lines
旁边留出一点空间。这应该在所有 iPhone 尺寸上正确显示。我现在在这方面太久了..
这应该是一个 1 分钟的任务,所以我可能有一些误解。如果有人可以在这里帮助我,我将非常感激:)
解决方案
向 oderLabel 添加具有适当大小的宽度锚点可能会奏效。
推荐阅读
- javascript - 具有水平滚动的 CSS 固定 div
- html - 使全屏背景图像在 5 秒后出现
- javascript - 在 React 中删除表数据 (td) 值后设置状态
- java - ECDH ServerKeyExchange 签名无效;嵌套异常是 javax.net.ssl.SSLHandshakeException: Invalid ECDH ServerKeyExchange signature
- python - 如何在 Windows 中连接 USB 到 SPI 通信。?
- wpf - 如何在 WPF 项目中组装命名空间
- terraform - 从 Azure 文件共享获取挂载脚本 - Terraform
- sql - 如何在此 SQL 中添加小计列(订购数量 x 标准价格)
- reactjs - 错误:https://registry.npmjs.org/react:无法建立隧道套接字
- list - Solace Subscriptions 是一个列表