PAVITHRAN R
PAVITHRAN R

Reputation: 45

Changing height of UITextField in default UIsearchBar

I am working with the Default Search Bar and I tried to change the height of the search bar with the following line,

for subView in search_bar.subviews
    {
        for subsubView in subView.subviews
        {
            if let textField = subsubView as? UITextField
            {
                textField.borderStyle = .roundedRect
               // var frameRect = textField.frame;
                //frameRect.size.height = 100; // <-- Specify the height you want here.
               // textField.frame = frameRect;
                textField.frame = CGRect(x: 0, y: 0, width: self.view.frame.width, height: 70)
                //textField.font = UIFont.systemFont(ofSize: 20)
            }
        }
    }

and it seems not working... can anyone help with this?

Upvotes: 2

Views: 702

Answers (1)

Abhinandan Pratap
Abhinandan Pratap

Reputation: 2148

Use this code it works:

for subView in search_bar.subviews where subView is UITextField {
    subView.frame = CGRect(x: 0, y: 0, width: subView.frame.size.width, height: 70)
}

Upvotes: 1

Related Questions