Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 如何防止一个UIView被另一个UIView隐藏?_Swift_Uiview_Uisegmentedcontrol - Fatal编程技术网

Swift 如何防止一个UIView被另一个UIView隐藏?

Swift 如何防止一个UIView被另一个UIView隐藏?,swift,uiview,uisegmentedcontrol,Swift,Uiview,Uisegmentedcontrol,我正在使用UIViews创建一个自定义的、可重用的分段控制器,但我遇到了视图重叠的问题。目前看起来是这样的: 你可以看到蓝色选择器在按钮下面,但我希望它位于底部,有四个像素高。为此,我必须: let numberOfButtons = CGFloat(buttonTitles.count) let selectorWidth = frame.width / numberOfButtons let selectorYPosition = frame.height - 3 <--- This

我正在使用
UIViews
创建一个自定义的、可重用的分段控制器,但我遇到了视图重叠的问题。目前看起来是这样的:

你可以看到蓝色选择器在按钮下面,但我希望它位于底部,有四个像素高。为此,我必须:

let numberOfButtons = CGFloat(buttonTitles.count)
let selectorWidth = frame.width / numberOfButtons
let selectorYPosition = frame.height - 3 <--- This cause it to be hidden behind the button
selector = UIView(frame: CGRect(x: 0, y: selectorYPosition, width: selectorWidth, height: 4))
selector.layer.cornerRadius = 0
selector.backgroundColor = selectorColor
addSubview(selector)
bringSubviewToFront(selector) <--- I thought this would work but it does nothing

您正在用stackView覆盖您的
选择器

您需要执行以下操作:

bringSubviewToFront(selector)

添加所有视图后。将该行移动到
updateView()

的底部,执行
stackView.bringsubview-tofront(选择器)
时会发生什么?我刚刚添加了
stackView.bringsubview-tofront(选择器)
,但没有效果。谢谢你。
bringSubviewToFront(selector)