gpt4 book ai didi

ios - 更改 iOS 中 UISearchBar 范围按钮的高度?

转载 作者:搜寻专家 更新时间:2023-10-31 08:26:44 25 4
gpt4 key购买 nike

我想更改搜索栏范围按钮的高度。我正在使用调整后的分段控件,并想让示波器按钮看起来一样。下面是我的范围按钮的屏幕截图和我想要匹配的分段控件的另一个屏幕截图。

这是我用于分段控件的代码,可能需要重新应用于搜索栏范围按钮,但不知道如何:

    filterSegmentedControl.frame = CGRect(
x: filterSegmentedControl.frame.origin.x,
y: filterSegmentedControl.frame.origin.y,
width: filterSegmentedControl.frame.size.width,
height: 22)

我当前的搜索栏范围按钮: enter image description here

我的分段控件: enter image description here

最佳答案

分段控件不会从 UISearchBar 界面中公开。因此,您无法控制其中的分段控件的框架。如果您真的想更改框架高度,除了遍历 subview 以找到 UISegmentedControl 然后手动为其设置框架外,我看不到任何其他方法。

这是 UIView 上的一个小助手扩展,它将帮助您遍历 UISearchBar 中的 subview 层次结构以找到 UISegmentedControl。

extension UIView {

func traverseSubviewForViewOfKind(kind: AnyClass) -> UIView? {
var matchingView: UIView?

for aSubview in subviews {
if aSubview.dynamicType == kind {
matchingView = aSubview
return matchingView
} else {
if let matchingView = aSubview.traverseSubviewForViewOfKind(kind) {
return matchingView
}
}
}

return matchingView
}
}

然后您可以使用此方法手动为找到的分段控件设置框架,就像这样,

if let segmentedControl = searchBar.traverseSubviewForViewOfKind(UISegmentedControl.self) {
var segmentedControlFrame = segmentedControl.frame
segmentedControlFrame.size.height = 70
segmentedControl.frame = segmentedControlFrame
}

关于ios - 更改 iOS 中 UISearchBar 范围按钮的高度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30465310/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com