Git Product home page Git Product logo

stylablenavigationbar's Introduction

StylableNavigationBar

Version License Platform

🧸 StylableNavigationBar provide a lightweight replacement for a standard UINavigationController, so you can easily manage your navigation and status bar styles throughout your iOS app

Example

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

Requirements

iOS 11, Swift 5

Installation

  1. StylableNavigationBar is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'StylableNavigationBar'
  1. Replace class for your UINavigationController to StylableNavigationController. If you are using Storyboard, you can change it using the Inspector at the right side of the Xcode:

StylableNavigationBar Storyboard

  1. If you creating navigation controller from code you can do it same way as when you create a normal UINavigationController:
let navigationController = StylableNavigationController(rootViewController: childViewController)
  1. Define preffered bar style for child view controller by making its extension:
// MARK: Bar Style
extension ViewController: NavigationBarStylable {
    
    var navigationBarStyle: NavigationControllerStyle? {
        return .darkTinted(tintColor: .black)
    }
}
  1. Done.

Navigation Bar Styling

There are two ways to define navigation bar style

  1. Use predefined NavigationControllerStyle like .darkTinted .lightTinted and specify a tint color:
// MARK: Define Navigation Bar Style
extension ViewController: NavigationBarStylable {
    
    var navigationBarStyle: NavigationControllerStyle? {
        return .lightTinted(tintColor: .lightGray)
    }
}
  1. Create your own style (e.g. AppMainNavigationBarStyle) conforming to NavigationBarStyleProtocol:
// MARK: Default Navigation Bar Style
struct AppMainNavigationBarStyle: NavigationBarStyleProtocol {
    var barColor: UIColor? = UIColor(named: "defaultBarColor")
    var tintColor: UIColor = UIColor(named: "defaultTintColor") ?? UIColor()
    var statusBarStyle: UIStatusBarStyle = .lightContent
}

class ViewController: UIViewController {
    var barStyle: NavigationBarStyleProtocol = AppMainNavigationBarStyle()
}

// MARK: Define Navigation Bar Style
extension ViewController: NavigationBarStylable {
    
    var navigationBarStyle: NavigationControllerStyle? {
        return .custom(style: barStyle)
    }
}

Roadmap

  • Handle iOS 11 NavigationController's largeTitle
  • Add an ability to define image as a navigation bar's background
  • Allow to define title styles (e.g. two lines title etc.)

Author

Pavlo Chernovolenko, Linkedin

I will appreciate your contribution in case you have any ideas how to improve the component. Please raise issues if something is not working as expected.

License

StylableNavigationBar is available under the MIT license. See the LICENSE file for more info.

stylablenavigationbar's People

Contributors

chernovolenko avatar pchernovolenko avatar

Stargazers

 avatar

Watchers

 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.