📜  使用阴影 swift 6 向 UIView 的特定角落添加阴影 site:stackoverflow.com - Swift 代码示例

📅  最后修改于: 2022-03-11 15:01:02.239000             🧑  作者: Mango

代码示例1
let containerV = UIView(frame: CGRect(x: 0, y: 0, width: self.frame.size.width , height: 50))
containerV.clipsToBounds = false
containerV.layer.shadowColor = UIColor.black.cgColor
containerV.layer.shadowOpacity = 1 
containerV.layer.shadowOffset = CGSize(width: -0.5, height: -3.0) 
/* since we dont want shadow at bottom */
containerV.layer.shadowRadius = 2
containerV.layer.shadowPath = UIBezierPath(roundedRect: containerV.bounds, 
cornerRadius: 10).cgPath

let headerLabel  = UILabel()
headerLabel.frame = containerV.bounds
headerLabel.text = "Test Header"
headerLabel.backgroundColor = UIColor.white

headerLabel.clipsToBounds = true
headerLabel.layer.cornerRadius = 10
if #available(iOS 11.0, *) {
        headerLabel.layer.maskedCorners = [.layerMinXMinYCorner, .layerMaxXMinYCorner]
    } else {
        // Fallback on earlier versions
    }
containerV.addSubview(headerLabel)