gpt4 book ai didi

ios - 从 InterfaceBuilder 和通过代码设置时获得不同的颜色

转载 作者:搜寻专家 更新时间:2023-11-01 06:34:38 25 4
gpt4 key购买 nike

<分区>

我正在通过 UIView 扩展为 UITextField 设置一些边框,如下所示。

extension UIView {

func border(side: BorderSide = .all, color:UIColor = UIColor.black, borderWidth:CGFloat = 1.0) {

let border = CALayer()
border.borderColor = color.cgColor
border.borderWidth = borderWidth

switch side {
case .all:
self.layer.borderWidth = borderWidth
self.layer.borderColor = color.cgColor
case .top:
border.frame = CGRect(x: 0, y: 0, width:self.frame.size.width ,height: borderWidth)
case .bottom:
border.frame = CGRect(x: 0, y: self.frame.size.height - borderWidth, width:self.frame.size.width ,height: borderWidth)
case .left:
border.frame = CGRect(x: 0, y: 0, width: borderWidth, height: self.frame.size.height)
case .right:
border.frame = CGRect(x: self.frame.size.width - borderWidth, y: 0, width: borderWidth, height: self.frame.size.height)
case .cusomRight:
border.frame = CGRect(x: self.frame.size.width - borderWidth - 8, y: 8, width: borderWidth, height: self.frame.size.height - 16)
}

if side.rawValue != 0 {
self.layer.addSublayer(border)
self.layer.masksToBounds = true
}

}
}

并通过这条线生效。

let color = UIColor.hexStringToUIColor(hex: "#1F271B")
txtLongitude.border(side: .bottom, color: color, borderWidth: 1)

而另一方面,我将 UIView 作为 UITextView 的边框。并从 InterfaceBuilder 提供背景颜色。如下图所示。
Setting color via InterfaceBuilder

但是当我运行应用程序时。我通过 InterfaceBuilder 获得了不同的颜色。这是屏幕截图。
Color which is gave by code
Color which is gave by InterfaceBuilder
我可以通过编码设置两种颜色,但我想知道为什么会这样,而我正在从 InterfaceBuilder 设置颜色?

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