在默认的UIsearchBar中更改UITextField的高度

时间:2017-11-01 10:07:25

标签: ios swift3

我正在使用默认搜索栏,我尝试使用以下行更改搜索栏的高度,

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)
            }
        }
    }

似乎没有用......有人可以帮忙吗?

1 个答案:

答案 0 :(得分:1)

使用此代码:

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