gpt4 book ai didi

ios - 用 subview 隐藏彩色边框

转载 作者:行者123 更新时间:2023-11-28 11:33:28 25 4
gpt4 key购买 nike

我有带彩色边框的 uiview。我想在上面添加一个 subview ,所以它“隐藏”了父 View 边框。目前,当我尝试在上面添加一个 View (UILabel 的子类)时,它不会像我想要的那样重叠任何东西。我想要的是在与标签框架交互时删除白线。

enter image description here

我的类(class)是:

class LabeledContainerView: UIView {

var text: String!
var height: CGFloat!
var offset: CGFloat!

var label: UILabel = {
let lbl = LabelSL.create(textColor: Theme.Color.white,
font: Theme.Font.regular())
lbl.text = Strings.login.value
lbl.backgroundColor = Theme.Color.clear.value
return lbl
}()

init(text: String,
height: Double,
offset: Double) {
super.init(frame: CGRect(x: 0, y: 0, width: 0, height: 0))
self.text = text
self.height = CGFloat(height)
self.offset = CGFloat(offset)
createUI()
setConstraints()
}

required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}

func highlight(){

}

func turnOffHighlight(){

}

private func createUI(){
translatesAutoresizingMaskIntoConstraints = false
clipsToBounds = false
layer.cornerRadius = 4.0
layer.borderColor = UIColor.white.cgColor
layer.borderWidth = 2.0
addSubview(label)
}

private func setConstraints(){
let tinyOffset: CGFloat = 2

label.leftAnchor.constraint(equalTo: leftAnchor, constant: offset + tinyOffset).isActive = true
label.centerYAnchor.constraint(equalTo: topAnchor).isActive = true
}
}

最佳答案

您无需在其上方添加其他 View 即可做到这一点。然后将您的文本字段委托(delegate)设置为 self

func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
if textField.text?.isEmpty ?? false{
//yourView.hideBorders
}
}

如果我没明白你的意思,请澄清

关于ios - 用 subview 隐藏彩色边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56275915/

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