// MARK:给视图添加边框,给图像视图添加圆角效果,给图像视图添加阴影效果
private func addLayer(){
let img = UIImage(named: "image")
let imgView = UIImageView(frame: CGRect(x: 24, y: 88, width: 300, height: 300))
imgView.image = img
imgView.layer.borderWidth = 10
imgView.layer.borderColor = UIColor.lightGray.cgColor
// imgView.layer.cornerRadius = 150
// imgView.layer.masksToBounds = true
imgView.layer.shadowColor = UIColor.black.cgColor
imgView.layer.shadowOffset = CGSize(width: 10.0, height: 10.0)
imgView.layer.shadowOpacity = 0.45
imgView.layer.shadowRadius = 10
self.view.addSubview(imgView)
}
// MARK:UIView视图渐变填充
private func viewGradientFilling(){
let rect = CGRect(x: 30, y: 60, width: 200, height: 200)
let gradientView = UIView(frame: rect)//初始化一个视图对象,作为渐变图形的容器
let gradientLayer = CAGradientLayer()//新建一个渐变层
gradientLayer.frame = gradientView.frame//设置渐变层的位置和尺寸,与视图对象保持一致
let fromColor = UIColor.yellow.cgColor //设置渐变色的起始颜色为黄色
let midColor = UIColor.red.cgColor //设置渐变色的中间颜色为红色
let toColor = UIColor.purple.cgColor//设置渐变的颜色为紫色
gradientLayer.colors = [fromColor,midColor,toColor];//将颜色的数组赋值给颜色渐变层的颜色数组属性
gradientView.layer.addSublayer(gradientLayer)//将配置好的渐变层添加到视图对象的层中
self.view.addSubview(gradientView)
}
// MARK:UiView视图的纹理填充
private func textureFillingOfViews(){
// 将导入的图片作为纹理,平铺整个屏幕
let image = UIImage(named: "image")
let patternColor = UIColor.init(patternImage: image!)
self.view.backgroundColor = patternColor
}