纯代码的方式写:
效果图
下面是代码:
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let image = UIImage(named: "img1")
let imageView = UIImageView(image: image)
imageView.frame = CGRect(x: 0, y: 0, width: 300, height: 500)
self.view.addSubview(imageView)
// 初始化一个模糊效果对象(可以制作毛玻璃效果)
let blur = UIBlurEffect(style: .light)
// 初始化一个基于模糊效果的视觉效果视图
let blurView = UIVisualEffectView(effect: blur)
blurView.frame = CGRect(x: 40, y: 40, width: 200, height: 200)
blurView.layer.cornerRadius = 30
blurView.layer.masksToBounds = true
imageView.addSubview(blurView)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
storyboard的方式:
效果图
用到的控件