iOS 实现毛玻璃效果

1, UIImage 图片加滤镜,CoreImage(CIImage,iOS6+), Accelerate,GPUImage等
2,iOS7+, 使用view自己的type,用view内部处理。 比如UIToolBar
3,iOS8+, 使用UIVisualEffectView
4,UIStoryboard拖拽UIVisualEffectView的使用方法?

Visual Effect View with Blur
Visual Effect Views with Blur and Vibrancy

这两种view都是UIVisualEffectView,UIVisualEffectView的contentView还可以嵌套一个UIVisualEffectView, 被嵌套的UIVisualEffectView的vibrancy属性不一样。一个是true,另一个是false,它决定了毛玻璃上的view的显示效果。

在代码中,并没有直接设置vibrancy属性的。而是通过使用UIVibrancyEffect初始化,为false的话就是使用UIBlurEffect初始化。

Paste_Image.png

Visual Effect Views with Blur and Vibrancy
直接拖拽它的效果等价于拖拽一个Visual Effect View with Blur,然后在它的contentView上再拖拽一个Visual Effect View with Blur,第二个 Visual Effect View with Blur 设置Blue Style 的Vibrancy的状态为选中状态。

Paste_Image.png
let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.light)
let vibrancyEffect = UIVibrancyEffect(blurEffect: blurEffect)
let blurEffectView = UIVisualEffectView(effect: blurEffect)
let vibrancyEffectView = UIVisualEffectView(effect: vibrancyEffect)

let label:UILabel = UILabel()
label.text = "helloworld"
label.font = UIFont.systemFont(ofSize: 80)
label.sizeToFit()
label.textColor = UIColor.red
label.center = CGPoint(x: 100, y: 100)

let label2:UILabel = UILabel()
label2.text = "helloworld 2"
label2.font = UIFont.systemFont(ofSize: 80)
label2.sizeToFit()
label2.textColor = UIColor.red
label2.center = CGPoint(x: 200, y: 200)
 blurEffectView.frame = view.bounds
vibrancyEffectView.frame = view.bounds

vibrancyEffectView.contentView.addSubview(label)
blurEffectView.contentView.addSubview(vibrancyEffectView)
blurEffectView.contentView.addSubview(label2)
view.addSubview(blurEffectView)


参考//www.greatytc.com/p/6dd0eab888a6

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容