今是昨非

今是昨非

日出江花红胜火,春来江水绿如蓝

iOS 15 Navigation Bar Settings

Setting the Navigation Bar in iOS 15#

Background#

When running the project on iOS 15 using Xcode 13.0, the navigation bar appears black. However, there are no issues when running on lower versions of Xcode.

Modifications#

The method of setting needs to be modified, please refer to barTintColor not working in iOS 15

The original code for setting the navigation bar remains unchanged. Add the properties of the UINavigationBarAppearance instance object and assign them to the global navigationBar or the navigationBar property of individual pages, depending on whether the project's setting is a global NavigationBar or a single page setting (refer to iOS StatusBar Setting).

The code is as follows:


- (void)updateNavigationBarColor:(UIColor *)color {
    UINavigationBar *bar = self.navigationController.navigationBar;
    if (@available(iOS 13.0, *)) {
        UINavigationBarAppearance *barAppearance = [UINavigationBarAppearance new];
        barAppearance.backgroundColor = color; // Set the background color
        barAppearance.titleTextAttributes = @{NSForegroundColorAttributeName : [UIColor whiteColor],
                                              NSFontAttributeName : [UIFont fontWithName:@"Helvetica-Bold" size:17]}; // Set the font color and size of the navigation bar
        barAppearance.shadowColor = [UIColor clearColor]; // Hide the bottom line of the navigation bar
        
        bar.scrollEdgeAppearance = bar.standardAppearance = barAppearance;
        [bar setShadowImage:[UIImage new]];
    } else {
        // Fallback on earlier versions
    }
    [bar setBackgroundImage:[UIImage wps_createImageWithColor:color] forBarMetrics:UIBarMetricsDefault];
}

References#

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.