gpt4 book ai didi

ios - UITextField RightView 大小不正确

转载 作者:行者123 更新时间:2023-11-28 07:42:39 49 4
gpt4 key购买 nike

问题 enter image description here

UITextField 放置在 UIStackView 的 UICollectionView 单元格内时,rightView 未正确调整大小

代码:

  func configure(cell: UICollectionViewCell) {
guard let cell = cell as? ListTextFieldCell else {return}
self.cell = cell
cell.title.text = "PIN"
let textField = cell.textField!
textField.rightViewMode = .always
updateButtonTitle()
textField.rightView = revealPasswordButton
textField.placeholder = "4 digits"
textField.keyboardType = .numberPad
textField.delegate = self
updateButtonTitle()
// No effect!
revealPasswordButton.frame = CGRect(origin: .zero, size: CGSize(width: 100, height: 50))
}


// no effect WHATSOEVER
revealPasswordButton.setTitle(buttonTitle, for: .normal)
revealPasswordButton.setContentCompressionResistancePriority(.required, for: .horizontal)
revealPasswordButton.setContentCompressionResistancePriority(.required, for: .vertical)
revealPasswordButton.sizeToFit()
}

另一方面,在普通的 UIView 中,完全相同的代码会产生正确的结果:

enter image description here

这样的问题可能是什么情况

最佳答案

您的 UIStackView Distribution 设置是什么?此外,对于 rightView

,您可能还想将 contentCompressionResistancePriority 水平值设置为 UILayoutPriorityDefaultRequired

关于ios - UITextField RightView 大小不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51838624/

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