forked from Zero-zhou/iOS-Extensions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
UINavigationController+Ex.swift
53 lines (40 loc) · 1.69 KB
/
UINavigationController+Ex.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//
// UINavigationController+Ex.swift
//
// Created by Augus on 1/30/16.
// Copyright © 2016 iAugus. All rights reserved.
//
import UIKit
import SnapKit
extension UINavigationController {
func completelyTransparentBar() {
navigationBar.setBackgroundImage(UIImage(), for: .default)
navigationBar.shadowImage = UIImage()
navigationBar.isTranslucent = true
view.backgroundColor = UIColor.clear
navigationBar.backgroundColor = UIColor.clear
}
func transparentBlurBar() {
completelyTransparentBar()
let visualEffectView = UIVisualEffectView(effect: UIBlurEffect(style: .light))
// Do NOT insert to `navigationBar`, or the bar items will be covered.
// navigationBar.insertSubview(visualEffectView, belowSubview: navigationBar)
view.insertSubview(visualEffectView, belowSubview: navigationBar)
visualEffectView.snp.makeConstraints { (make) in
make.top.equalTo(view)
make.left.bottom.right.equalTo(navigationBar)
}
}
func blurBarWithColor(_ color: UIColor, alpha: CGFloat = 1) {
completelyTransparentBar()
let visualEffectView = UIVisualEffectView(effect: UIBlurEffect(style: .light))
visualEffectView.backgroundColor = color
visualEffectView.alpha = alpha
visualEffectView.isUserInteractionEnabled = false
navigationBar.insertSubview(visualEffectView, aboveSubview: navigationBar)
visualEffectView.snp.makeConstraints { (make) in
make.top.equalTo(navigationBar).offset(-22)
make.left.bottom.right.equalToSuperview()
}
}
}