UIImage
在视图图层上添加
let myLayer = CALayer() let myImage = UIImage(named: "star")?.cgImage myLayer.frame = CGRect(x: 0, y: 0, width: 60, height: 60) myLayer.cOntents= myImage myView.layer.addSublayer(myLayer)
添加UIImage
为子视图
let image = UIImage(named: "star") let imageView = UIImageView(image: image!) imageView.frame = CGRect(x: 0, y: 0, width: 60, height: 60) myView.addSubview(imageView)