当将rightView
放在UITextField
内的UICollectionView单元中时,UIStackView
的大小没有正确调整
代码:
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
中,完全相同的代码会产生正确的结果:
这种问题可能是什么情况
答案 0 :(得分:0)
您的UIStackView
分发设置是什么?另外,您可能希望将contentCompressionResistancePriority
UILayoutPriorityDefaultRequired
水平值设置为rightView