我使用了自定义UIView
类,其中包含文本字段和标签,由Storyboard提供。当类在类中添加子图层时,视图中包含的对象消失,变为透明或者可能变为UIView
背景的相同颜色。是否有可以设置的属性或使用的方法来确保对象保持可见?
提前致谢!
这是我的代码:
class viewBorder: UIView {
override init(frame: CGRect) {
super.init(frame: frame)
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override func drawRect(rect: CGRect) {
super.drawRect(rect)
// Create a rect with only 1x rounded corner
let rectPath = UIBezierPath(roundedRect: bounds, byRoundingCorners: UIRectCorner.TopLeft, cornerRadii: CGSize(width: 21.0, height: 21.0))
let rectLayer = CAShapeLayer()
rectLayer.shadowOffset = CGSize(width: -1.5, height: -1.5)
rectLayer.shadowOpacity = 0.6
rectLayer.path = rectPath.CGPath
rectLayer.fillColor = tintColor.CGColor
self.layer.addSublayer(rectLayer)
}
}