Xcode9学习笔记8 - UIView视图添加阴影效果

时间:2022-12-26 22:29:34

Xcode9学习笔记8 - UIView视图添加阴影效果

Xcode9学习笔记8 - UIView视图添加阴影效果

    override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let imageView = UIImageView(image: UIImage(named: "05"))
imageView.frame = CGRect(x: 36, y: 80, width: 248, height: 164)

let blackShadow = UIColor.black.cgColor //设置图像视图的阴影颜色为黑色
imageView.layer.shadowColor = blackShadow//设置图像视图的阴影颜色为黑色
imageView.layer.shadowOffset = CGSize(width: 10.0, height: 10.0)//设置图像视图层阴影的横向和纵向偏移值
imageView.layer.shadowOpacity = 0.45//设置图像视图层阴影透明度
imageView.layer.shadowRadius = 5.0//设置图像视图层阴影半径大小

self.view.addSubview(imageView)
}