【问题标题】:UIButton always truncate text on iOS 15UIButton 在 iOS 15 上总是截断文本
【发布时间】:2021-11-21 18:47:52
【问题描述】:

更新到 xcode 13 / ios 15 后。我明白了,UIButton 上的文本总是被截断,大小不固定。文本从 PushRelay (RxSwift) 传递。

See UIButton's on a horizontal UIStackView.

代码如下

  let tagButton = UIButton()
  addSubview(tagButton)
  tagButton.layer.cornerRadius = 16
  tagButton.layer.masksToBounds = true
  tagButton.titleEdgeInsets = UIEdgeInsets(top: 8, left: 16, bottom: 8, right: 16)
  tagButton.snp.makeConstraints({
    $0.edges.equalToSuperview()
  })

文本提供者:

  bag.insert(
    viewModel.outputs.titleAttrText
      .drive(tagButton.rx.attributedTitle(for: .normal))
  )
  

【问题讨论】:

    标签: uibutton rx-swift truncated ios15


    【解决方案1】:

    我在 UIStackView 中看到了这个问题。

    从 titleEdgeInsets 切换到 contentEdgeInsets 为我解决了这个问题。

    【讨论】:

      【解决方案2】:

      解决方案是titleEdgeInsets 属性。

      【讨论】:

      • 我认为这就是解决方案。如果您删除 titleEdgeInsets 属性,则该按钮可以正常工作。
      猜你喜欢
      • 1970-01-01
      • 2021-11-18
      • 2019-10-29
      • 2012-04-10
      • 2021-01-04
      • 1970-01-01
      • 2017-02-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多