import UIKit
class EffectViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
var imageDown = UIImageView(frame: CGRectMake(0, 0, self.view.frame.width, self.view.frame.height))
//设置背景图
imageDown.image = UIImage(named: "图片")
var imageUp = UIImageView(frame: CGRectMake(0, 0, 128, 128))
imageUp.center = CGPoint(x: self.view.frame.width, y: self.view.frame.height)
imageUp.image = UIImage(named: "头像图片")
//设置头像圆形
imageUp.layer.cornerRadius = 64
imageUp.clipsToBounds = true
let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.Light)
//创建效果实例
let blurView = UIVisualEffectView(effect: blurEffect)
//设置尺寸
blurView.frame.size = CGSize(width: view.frame.width, height: view.frame.height)
//把实例放入背景图
imageDown.addSubview
Swift模糊背景
最新推荐文章于 2024-09-11 19:47:57 发布
这篇博客介绍了如何使用Swift在iOS应用中实现模糊背景效果。通过创建UIImageView,设置背景图和头像,并利用UIBlurEffectStyle.Light创建轻度模糊效果,将模糊视图添加到背景上。此外,还提到了未来实践会探索使用scrollView.contentOffset来实现滑动时模糊效果的渐变。
摘要由CSDN通过智能技术生成