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)