swiftnslayoutanchor

How to convert heightAncor to CGFloat Type?


After changing the height of a UITextField using an animation, the Gradient Layer's height that is a subview doesn't match the parent height anynore.

I want to convert heightAncor of a view which is of type NSLayoutDimensons to CGFloat, so I can set the GradientLayer's frame.size.height equal to UITextField's heightAncor Is that even possible?


Solution

  • so I can set the GradientLayer's frame.size.height equal to UITextField's heightAncor Is that even possible?

    You don't need to read any values from the anchor, and it wouldn't do any good if you could. Constraints are merely instructions to the autolayout engine. You are not the engine, so constraints have little or no direct meaning to you.

    If you put your code into viewDidLayoutSubviews, the autolayout engine will have done its work, and now you can get the text field's frame.size.height or bounds.size.height directly (or any view's frame or bounds), and it will be correct.