2

The problem enter image description here

The rightView is not properly resized, when the UITextField is placed inside an UICollectionView cell inside an UIStackView

The code:

  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()
  }

On the other hand, in a normal UIView the very same code produces the correct result:

enter image description here

What could be the case of such a problem

Richard Topchii
  • 7,075
  • 8
  • 48
  • 115

1 Answers1

0

What is your UIStackView Distribution settings? Also you might want to set the contentCompressionResistancePriority Horizontal value to be UILayoutPriorityDefaultRequired for the rightView

TunaTheDog
  • 33
  • 6