【问题标题】:One line in UIButton iOS15UIButton iOS 15 中的一行
【发布时间】:2022-01-07 09:29:13
【问题描述】:

我有问题。我无法在 UIButton 中将 numberOfLines 设置为 1。要设置按钮,我使用 iOS 15 中的 UIButton.Configuration。这是我的带有长文本的按钮:

我想在按钮的末尾设置文本的结尾。我试过设置这个命令:

parentButton.titleLabel!.lineBreakMode = .byWordWrapping
parentButton.titleLabel!.numberOfLines = 1

和 NSLayoutConstraint

        parentButton.topAnchor.constraint(equalTo: textField.bottomAnchor,   constant: 12),
        parentButton.leftAnchor.constraint(equalTo: view.leftAnchor, constant: 25),
        parentButton.rightAnchor.constraint(lessThanOrEqualTo: view.rightAnchor, constant: -25),
        parentButton.heightAnchor.constraint(equalToConstant: 30),

它不起作用。有什么想法吗?

【问题讨论】:

  • 按钮的类型是什么?填满了吗?
  • 是的。有填充。
  • lineBreakMode 不应该是 .byTruncatingTail?

标签: swift uibutton uikit ios15


【解决方案1】:

使用上面写的前两行,只需将按钮样式更改为default

【讨论】:

  • 我的意思是在按钮末尾停止文本。我不需要将所有文本都放入按钮中。
  • 现在更新我的答案
猜你喜欢
  • 2021-12-08
  • 2022-07-22
  • 2021-11-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多