Skip to content

Commit

Permalink
Merge branch 'release/1.0.8'
Browse files Browse the repository at this point in the history
  • Loading branch information
pisces committed Aug 7, 2021
2 parents e84a9e3 + 3e3287d commit 70a5fcc
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 63 deletions.
6 changes: 3 additions & 3 deletions Example/UINavigationBarDecorator/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="17156" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="wTQ-u1-zmb">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="18122" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="wTQ-u1-zmb">
<device id="retina4_7" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="17126"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="18093"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
Expand Down Expand Up @@ -38,7 +38,7 @@
<real key="value" value="50"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="number" keyPath="contentInsetBottom">
<real key="value" value="50"/>
<real key="value" value="20"/>
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
</navigationBar>
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion UINavigationBarDecorator.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
88 changes: 46 additions & 42 deletions UINavigationBarDecorator/Classes/AdvancedNavigationBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
Expand Down
32 changes: 16 additions & 16 deletions UINavigationBarDecorator/Classes/PageSheetNavigationBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -67,7 +81,7 @@ open class PageSheetNavigationBar: AdvancedNavigationBar {
}
}

// MARK: - Variables
// MARK: - Private

private lazy var thumbLayer: CALayer = {
let layer = CALayer()
Expand All @@ -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
}
}

0 comments on commit 70a5fcc

Please sign in to comment.