diff --git a/Example/UINavigationBarDecorator/Base.lproj/Main.storyboard b/Example/UINavigationBarDecorator/Base.lproj/Main.storyboard index dd5b40c..8fa7be7 100644 --- a/Example/UINavigationBarDecorator/Base.lproj/Main.storyboard +++ b/Example/UINavigationBarDecorator/Base.lproj/Main.storyboard @@ -1,9 +1,9 @@ - + - + @@ -38,7 +38,7 @@ - + diff --git a/README.md b/README.md index f7c060c..03c01e8 100644 --- a/README.md +++ b/README.md @@ -189,7 +189,7 @@ $ brew install carthage To integrate Alamofire into your Xcode project using Carthage, specify it in your `Cartfile`: ```ogdl -github "pisces/UINavigationBarDecorator" ~> 1.0.6 +github "pisces/UINavigationBarDecorator" ~> 1.0.8 ``` Run `carthage update` to build the framework and drag the built `UINavigationBarDecorator.framework` into your Xcode project. diff --git a/UINavigationBarDecorator.podspec b/UINavigationBarDecorator.podspec index 34533a2..c2e26f3 100644 --- a/UINavigationBarDecorator.podspec +++ b/UINavigationBarDecorator.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.name = 'UINavigationBarDecorator' - s.version = '1.0.7' + s.version = '1.0.8' s.summary = 'Compatible UINavigationBarAppearance' s.description = 'Compatible UINavigationBarAppearance for all iOS versions' s.homepage = 'https://github.com/pisces/UINavigationBarDecorator' diff --git a/UINavigationBarDecorator/Classes/AdvancedNavigationBar.swift b/UINavigationBarDecorator/Classes/AdvancedNavigationBar.swift index 843f17d..d94feeb 100644 --- a/UINavigationBarDecorator/Classes/AdvancedNavigationBar.swift +++ b/UINavigationBarDecorator/Classes/AdvancedNavigationBar.swift @@ -34,7 +34,36 @@ import UIKit open class AdvancedNavigationBar: UINavigationBar { - // MARK: - Variables (Inspectables) + // MARK: - Lifecycle + + public override init(frame: CGRect) { + super.init(frame: frame) + initProperties() + sizeToFit() + } + + public required init?(coder: NSCoder) { + super.init(coder: coder) + initProperties() + } + + open override func layoutSubviews() { + super.layoutSubviews() + subviews.forEach { + $0.frame = frame(of: $0) + $0.sizeToFit() + } + } + + open override func sizeThatFits(_ size: CGSize) -> CGSize { + .init(width: size.width, height: navigationBarHeight) + } + + // MARK: - Open + + open func initProperties() { } + + // MARK: - Public @IBInspectable public var contentInsetLeft: CGFloat { @@ -76,63 +105,38 @@ open class AdvancedNavigationBar: UINavigationBar { setNeedsLayout() } } - - // MARK: - Variables (Input) - + public var barHeight: CGFloat { + Const.defaultBarHeight + contentInsets.top + contentInsets.bottom + } + public var navigationBarHeight: CGFloat { + UIApplication.shared.statusBarFrame.height + barHeight + } public var contentInsets: UIEdgeInsets = .zero { didSet { setNeedsLayout() } } - // MARK: - Variables - - public var navigationBarHeight: CGFloat { - 44 + contentInsets.top + contentInsets.bottom - } - - // MARK: - Constructors - - public override init(frame: CGRect) { - super.init(frame: frame) - initProperties() - sizeToFit() - } + // MARK: - Private - public required init?(coder: NSCoder) { - super.init(coder: coder) - initProperties() + private struct Const { + static let defaultBarHeight: CGFloat = 44 + static let backgroundViewName = "UIBarBackground" + static let contentViewName = "UINavigationBarContentView" } - - // MARK: - Overridden: UINavigationBar - - open override func layoutSubviews() { - super.layoutSubviews() - subviews.forEach { - $0.frame = frame(of: $0) - $0.sizeToFit() - } - } - - open override func sizeThatFits(_ size: CGSize) -> CGSize { - .init(width: size.width, height: navigationBarHeight) - } - - // MARK: - Functions - - open func initProperties() { } } extension AdvancedNavigationBar { + private func frame(of subview: UIView) -> CGRect { let name = NSStringFromClass(subview.classForCoder) - if name.contains("UIBarBackground") { - return CGRect(x: 0, y: 0, width: bounds.width, height: navigationBarHeight) + if name.contains(Const.backgroundViewName) { + return CGRect(x: 0, y: -UIApplication.shared.statusBarFrame.height, width: bounds.width, height: navigationBarHeight) } - if name.contains("UINavigationBarContentView") { + if name.contains(Const.contentViewName) { return CGRect( x: contentInsets.left, - y: (44 - subview.bounds.height) / 2 + contentInsets.top, + y: (Const.defaultBarHeight - subview.bounds.height) / 2 + contentInsets.top, width: bounds.width - contentInsets.left - contentInsets.right, height: subview.bounds.height) } diff --git a/UINavigationBarDecorator/Classes/PageSheetNavigationBar.swift b/UINavigationBarDecorator/Classes/PageSheetNavigationBar.swift index 5aff595..5c7bcfe 100644 --- a/UINavigationBarDecorator/Classes/PageSheetNavigationBar.swift +++ b/UINavigationBarDecorator/Classes/PageSheetNavigationBar.swift @@ -34,7 +34,21 @@ import UIKit open class PageSheetNavigationBar: AdvancedNavigationBar { - // MARK: - Variables (Inspectables) + // MARK: - Lifecycle + + open override func layoutSubviews() { + super.layoutSubviews() + thumbLayer.frame.origin = .init( + x: (bounds.width - thumbLayer.bounds.width) / 2, + y: (contentInsets.top - thumbLayer.bounds.height) / 2) + } + + open override func initProperties() { + layer.addSublayer(thumbLayer) + contentInsetTop = 24 + } + + // MARK: - Public @IBInspectable public var thumbHeight: CGFloat { @@ -67,7 +81,7 @@ open class PageSheetNavigationBar: AdvancedNavigationBar { } } - // MARK: - Variables + // MARK: - Private private lazy var thumbLayer: CALayer = { let layer = CALayer() @@ -76,18 +90,4 @@ open class PageSheetNavigationBar: AdvancedNavigationBar { layer.frame.size = .init(width: 44, height: 4) return layer }() - - // MARK: - Overridden: ABCNavigationBar - - open override func layoutSubviews() { - super.layoutSubviews() - thumbLayer.frame.origin = .init( - x: (bounds.width - thumbLayer.bounds.width) / 2, - y: (contentInsets.top - thumbLayer.bounds.height) / 2) - } - - open override func initProperties() { - layer.addSublayer(thumbLayer) - contentInsetTop = 24 - } }