看了老郑的模糊效果,所以自己也做了一个,感觉还不错
用到以下知识
随后是代码部分的关联
一个是背景imageView.还有一个是前面的imageVIew
@IBOutlet var bg: UIImageView!
@IBOutlet var tuBiao: UIImageView!
随后在viewDIdLoad中添加如下代码
//设置图标的圆角大小
tuBiao.layer.cornerRadius = 50
//这句话一定要设为true,否则无法出现圆角设置
tuBiao.clipsToBounds = true
//创建模糊效果实例,模糊效果的样式会有所不同
let alert = UIBlurEffect(style: UIBlurEffectStyle.Light)
//创建效果图实例,继承自模糊效果实例
let effectView = UIVisualEffectView(effect: alert)
//设置效果图的尺寸大小
effectView.frame.size = CGSizeMake(view.frame.size.width, view.frame.size.height)
//将view添加到自己的视图中
bg.addSubview(effectView)
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
整体的代码如下
//
// ViewController.swift
// shiyan25
//
// Created by HISE_CS on 15/10/13.
// Copyright © 2015年 HISE_CS. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
@IBOutlet var bg: UIImageView!
@IBOutlet var tuBiao: UIImageView!
override func viewDidLoad() {
//设置图标的圆角大小
tuBiao.layer.cornerRadius = 50
//这句话一定要设为true,否则无法出现圆角设置
tuBiao.clipsToBounds = true
//创建模糊效果实例,模糊效果的样式会有所不同
let alert = UIBlurEffect(style: UIBlurEffectStyle.Light)
//创建效果图实例,继承自模糊效果实例
let effectView = UIVisualEffectView(effect: alert)
//设置效果图的尺寸大小
effectView.frame.size = CGSizeMake(view.frame.size.width, view.frame.size.height)
//将view添加到自己的视图中
bg.addSubview(effectView)
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
最后的效果图如图
感觉还是不错的