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.
- πΉ 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
- πΉ
Hereβs an example of CustomNav:
When presenting a view controller using present(), the navigation bar does not appear by default.
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.
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
)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.
Feel free to fork, improve, and submit pull requests!
For issues & feature requests, open a GitHub issue.
π Enjoy CustomNav! π
