Skip to content

lymanny/iOS-CustomNav

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“± iOS-CustomNav

A sample project that demonstrates a customizable navigation bar extension for UIKit, enhancing the default navigation bar with custom titles, subtitles, buttons, animations, and spacing controls.


✨ Features

  • πŸ”Ή Custom Titles & Subtitles with adjustable spacing
  • πŸ”Ή Dynamic Left & Right Buttons (supports images and text)
  • πŸ”Ή Title with Image Support (custom positioning, adjustable size & padding)
  • πŸ”Ή Customizable Spacing for title, subtitle, and buttons
  • πŸ”Ή Navigation Bar Customization:
    • πŸ”Ή isHidden β†’ Show or hide the navigation bar
    • πŸ”Ή barTintColor β†’ Set the background color
    • πŸ”Ή titleConfig β†’ Configure title text, font, size, color, and image
    • πŸ”Ή subtitleConfig β†’ Add an optional subtitle with styling options
    • πŸ”Ή leftButtons β†’ Add buttons on the left side of the navigation bar
    • πŸ”Ή rightButtons β†’ Add buttons on the right side of the navigation bar
    • πŸ”Ή titleSubtitleSpacing β†’ Adjust the spacing between title and subtitle
    • πŸ”Ή btnLeftRightSpacing β†’ Customize spacing between buttons

πŸ–Ό Screenshot

Here’s an example of CustomNav:

Custom Navigation Bar


πŸ“Œ Known Issue

πŸ“ˆ Navigation Bar Not Showing When Presenting a View Controller

When presenting a view controller using present(), the navigation bar does not appear by default.

Solution:

Wrap the presented view controller inside a UINavigationController:

@objc func presentCartView() {
    let cartVC = CartViewVC()
    let navController = UINavigationController(rootViewController: cartVC)
    navController.modalPresentationStyle = .fullScreen // Optional: Present full screen
    present(navController, animated: true, completion: nil)
}

Now, setNavigationBarStyle() will work properly in CartViewVC.


πŸ“Œ How to Use

1️⃣ Set Up the Custom Navigation Bar

setNavigationBarStyle(
    isHidden: false, // Show navigation bar
    barTintColor: UIColor.cyan, // Background color
    titleConfig: NavigationTitleConfig(
        title: "Cart View", // Set title
        titleImage: UIImage(named: "icon"), // Title image
        titleImageSize: CGSize(width: 18, height: 16), // Custom title image size
        titleFontName: "System", // Font name
        titleFontSize: 16, // Font size
        titleFontWeight: .semibold, // Font weight
        titleColor: .black, // Title color
        titleImageDirection: .trailing, // Image position
        titleImagePadding: 4, // Space between text and image
        titleSelector: #selector(handleTitleTap) // Title tap action
    ),
    subtitleConfig: NavigationSubtitleConfig(
        subtitle: "Items", // Subtitle text
        subtitleFontName: "System", // Subtitle font
        subtitleFontSize: 12, // Subtitle font size
        subtitleFontWeight: .regular, // Font weight
        subtitleColor: .gray // Subtitle color
    ),
    leftButtons: [
        NavigationButtonConfig(image: UIImage(named: "back"), selector: #selector(handleBack)) // Back button
    ],
    rightButtons: [
        NavigationButtonConfig(image: UIImage(named: "plus"), selector: #selector(handleAddItem)), // Plus button
        NavigationButtonConfig(titleConfig: ButtonTitleConfig(
            title: "Checkout", // Button title
            titleFontName: "System", // Font name
            titleFontSize: 16, // Font size
            titleFontWeight: .medium, // Font weight
            titleColor: .systemBlue // Font color
        ), selector: #selector(handleCheckout)) // Checkout button
    ],
    titleSubtitleSpacing: 0, // No space between title & subtitle
    btnLeftRightSpacing: 10 // Space between buttons
)

πŸ“„ License & Credits

This project is licensed under the MIT License.

The setNavigationBarStyle function was originally developed by KOSIGN iOS Developers.
I have modified and improved the entire implementation, including:

  • πŸ”Ή Title Configuration (supports title images, spacing, and customization)
  • πŸ”Ή Subtitle Configuration (adjustable font, color, and size)
  • πŸ”Ή Left & Right Button Customization (image/text-based buttons)
  • πŸ”Ή Title-Subtitle Spacing Control (titleSubtitleSpacing)
  • πŸ”Ή Custom Button Spacing (btnLeftRightSpacing)

See the License file for more details.


🎯 Contributions & Feedback

Feel free to fork, improve, and submit pull requests!
For issues & feature requests, open a GitHub issue.


πŸš€ Enjoy CustomNav! 😊

About

🍎 Sample project that demonstrates a customizable navigation bar.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages