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)