swift笔记--使用UIBlurEffect给图片加模糊效果(毛玻璃)

import UIKit

class ViewController:UIViewController {

override func viewDidLoad(){

super.viewDidLoad()

//在加载视图后进行任何其他设置,通常是从笔尖。

让image = UIImage(命名为:“img1”)

让imageView = UIImageView(图片:图片)

imageView.frame = CGRect(x:0,y:0,width:300,height:500)

self.view.addSubview(ImageView的)

//初始化一个模糊效果对象(可以制作毛玻璃效果)

让blur = UIBlurEffect(style:.light)

//初始化一个基于模糊效果的视觉效果视图

让blurView = UIVisualEffectView(效果:模糊)

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()

//处理可以重新创建的任何资源。

}

}

猜你喜欢

转载自blog.csdn.net/weixin_41735943/article/details/81175629