Yusuf Ak
Yusuf Ak

Reputation: 781

Change height of text field in search bar without searchcontroller swift

I have a problem about resizing text field inside the search bar which is implemented as a designable custom xib without any search controller.

I am able to set intrinsic size for my search bar but when I changed height of search bar, distance between text field and border increases. Here are what I need to get and what I actually get.

What I need to have

What I have now

I can get textField subview of searchBar by using "searchField" key value. I have tried to change its frame size but nothing has changed. I have also tried to set constraints but it didn't work as well.

let textField = value(forKey: "searchField") as! UITextField
textField.clipsToBounds = true
textField.layer.cornerRadius = 15.0
textField.frame.size.height = 10

(Note: Since I also need to have a text field with curved corners, changing border style of text field is not okay for my case. If there's a way of setting corner radius as in the picture with borderless textfield, that solution is also appreciated.)

I'm sorry if there's already an answer to my question but I couldn't find one after a detailed research. I will be thankful for any help.

Upvotes: 3

Views: 2957

Answers (1)

Student
Student

Reputation: 423

The constraints might be affecting the textField.frame.size.height = 10. What I suggest is that you go with constraints because you get more customizations. If you do so, you must delete textField.frame.size.height = 10. Also can you include the designable class in your post? That might be a solution/problem.

Upvotes: 1

Related Questions