【发布时间】:2019-10-16 09:21:18
【问题描述】:
有机会改变UISearchBar 的UITextField 高度吗?
我尝试了几乎所有我能找到的解决方案,但都没有成功。
更新:
我意识到ios13 searchBar不包含UITextField,但包含UISearchBarTextField类
这里是层次结构
据我了解,我们必须寻找 iOS13 的新类而不是 UITextField
我试过循环和搜索 TextField
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
for subView in searchBar.subviews {
for subsubView in subView.subviews{
for subsubsubView in subsubView.subviews{
if #available(iOS 13.0, *) {
if let textField = subsubsubView as? UISearchTextField{
var bounds: CGRect
bounds = textField.frame
bounds.size.height = 40 //(set height whatever you want)
textField.bounds = bounds
textField.layoutIfNeeded()
}
} else {
if let textField = subsubView as? UITextField {
var bounds: CGRect
bounds = textField.frame
bounds.size.height = 40 //(set height whatever you want)
textField.bounds = bounds
}
}
}
}
}
}
调试器进入状态,发现 UITextField 并改变了高度,但在设备上 - 没有高度变化
【问题讨论】:
-
您是否尝试过循环 UISearchBar 的子视图并更改 UITextField(这是子视图之一)的高度?
-
你用什么方法做的改变?您是否尝试过触发 layoutIfNeeded..?
-
我们可以对文本字段应用比例变换吗?
-
@denis_lor 是的。我已经尝试循环和 layoutIfNeed 调用并尝试在 willViewAppear 中更改高度。没有任何帮助