UITextField rightView alignment

105 Views Asked by At

I have a UITextField which contains a UIStackView constrained to parent bounds. Inside this stackView I have 3 subViews: title label, placeholder(following text rect frame) and a helper bottom label.

enter image description here

Notice that: "Text link" is the problematic rightView

I have also a rightView which is a button and I need to place it just in the midY of the parent bounds as it behaves in normal circumstances.

The UITextField rightView alignment works well without having a title label but when I insert into the stack a titleLabel, the rightView goes up.

I could manage this misalignment using insets but I have to support dynamic font so I can't have hardcoded insets. How could I place my rightView in the correct frame? Have I missed any layoutSubviews call?

Thanks!

1

There are 1 best solutions below

0
On BEST ANSWER

I have solve this by overriding rightViewRect(forBounds bounds: CGRect) -> CGRect adding the title height and spacing to the "Y" origin.

And please, if you vote negative, add some feedback in order to improve...