I have TextField in my UI and I have given dynamic height(using Storyboard) for wC x hR and wR x hR, now when I add corner radius to the textfield programmatically textField.layer.cornerRadius = textField.frame.height/2,
I am getting the height which I have set for wC x hR.
Is there any method by which I can get the actual height used in the iPad or iPhone device?
I am getting 40 instead of 70 in iPad with wR x hR
Use this image for reference
You are likely setting the
.cornerRadiusat the wrong point in the view layout... that is, you are calculatingtextField.frame.height/2before auto-layout sets the actual height.Much easier approach is to sub-class
UITextFieldand overridelayoutSubviews(), where you will update the.cornerRadiusvalue:Assign the Custom Class of your text field to
RoundTextField... in every other way, you can treat it as a standard text field.