Coder Social home page Coder Social logo

pisces / uinavigationbardecorator Goto Github PK

View Code? Open in Web Editor NEW
7.0 0.0 0.0 733 KB

Compatible UINavigationBarAppearance for all iOS versions

License: BSD 2-Clause "Simplified" License

Ruby 3.09% Swift 95.27% Objective-C 1.63%
uinavigationbarappearance uinavigationbar compatible decorator style theme ios13 custom custom-navigationbar ios10 ios11 ios12 ios14 carthage navigation ios9

uinavigationbardecorator's Introduction

UINavigationBarDecorator

Swift CI Status Version License Platform Carthage Compatible

Compatible UINavigationBarAppearance for all iOS versions

Features

  • Provide AdvancedNavigationBar is able to change size
  • Easy to apply navigation bar style for all iOS versions
  • Apply navigation bar style as one interface for all iOS versions
  • Provide compatible UINavigationBarAppearance for versions below iOS 13
  • Provide CompatibleNavigationBarAppearance like UINavigationBarAppearance that is available on iOS 13 higher
  • Automatically apply appearance to navigation bar through the view controller life cycle

Demo

Normal title on iOS 10.x

Large title on iOS 11.x

Large title on iOS 13 higher

Custom NavigationBar

AdvancedNavigationBar with Interface Builder

PageSheetNavigationBar with Interface Builder

Using Programacally

let navigationController = UINavigationController(
    rootViewController: #{YourVC}, 
    navigationBarClass: PageSheetNavigationBar.self)

UINavigationBarDecorator

Using with factory

class AppDelegate: UIResponder, UIApplicationDelegate {
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        UINavigationBarDecorator.isAllowsSwizzleLifeCycleOfViewController = true
        UINavigationBarDecorator.factory = SampleNavigationBarDecoratorFactory()
        return true
    }
}
struct SampleNavigationBarDecoratorFactory: UINavigationBarDecoratorFactory {
    func create(of vc: UIViewController) -> UINavigationBarDecorator? {
        switch vc {
        case is RootViewController:
            return .init(standard: .orange, compact: .orange, scrollEdge: .orange)
        case is SecondViewController:
            return .init(standard: .purple, compact: .purple, scrollEdge: .purple)
        default:
            return nil
        }
    }
}

extension CompatibleNavigationBarAppearance {
    static var purple: CompatibleNavigationBarAppearance {
        let appearance = CompatibleNavigationBarAppearance()
        appearance.backgroundColor = .purple
        appearance.tintColor = .white
        appearance.largeTitleTextAttributes = [
            .foregroundColor: UIColor.white
        ]
        appearance.titleTextAttributes = [
            .foregroundColor: UIColor.white,
            .font : UIFont.systemFont(ofSize: 17, weight: .semibold)
        ]
        return appearance
    }
    static var orange: CompatibleNavigationBarAppearance {
        let appearance = CompatibleNavigationBarAppearance()
        appearance.backgroundColor = .orange
        appearance.tintColor = .black
        appearance.largeTitleTextAttributes = [
            .foregroundColor: UIColor.black
        ]
        appearance.titleTextAttributes = [
            .foregroundColor: UIColor.black,
            .font : UIFont.systemFont(ofSize: 17, weight: .semibold)
        ]
        return appearance
    }
}

Using without factory

  • set the decorator directly on the view controller
final class ViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        navigationBarDecorator = .init(standard: .orange, compact: .orange, scrollEdge: .orange)
    }
}

Apply decorator manually

class AppDelegate: UIResponder, UIApplicationDelegate {
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        UINavigationBarDecorator.isAllowsSwizzleLifeCycleOfViewController = false
        UINavigationBarDecorator.factory = SampleNavigationBarDecoratorFactory()
        return true
    }
}

final class SampleNavigationController: UINavigationController {
    override var childForStatusBarStyle: UIViewController? {
        topViewController
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        delegate = self
    }
}

extension SampleNavigationController: UINavigationControllerDelegate {
    func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool) {
        viewController.navigationBarDecorator?.decorate(to: viewController)
    }
    func navigationController(_ navigationController: UINavigationController, didShow viewController: UIViewController, animated: Bool) {
        viewController.navigationBarDecorator?.decorate(to: viewController, by: viewController.view.frame.size)
    }
}

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

iOS SDK 9.0 equal or higher

Installation

UINavigationBarDecorator is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "UINavigationBarDecorator"

Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

To integrate Alamofire into your Xcode project using Carthage, specify it in your Cartfile:

github "pisces/UINavigationBarDecorator" ~> 1.0.8

Run carthage update to build the framework and drag the built UINavigationBarDecorator.framework into your Xcode project.

Author

Steve Kim, [email protected]

License

UINavigationBarDecorator is available under the BSD license. See the LICENSE file for more info.

uinavigationbardecorator's People

Contributors

pisces avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.