iOS 7 : Disable UINavigationBar Translucency For Entire App

后端 未结 9 1853
Happy的楠姐
Happy的楠姐 2020-12-14 14:12

Is there a way to disable UINavigationBar Translucency for an entire application?

I\'m aware that using [self.navigationController.navigationBar setTranslucent

9条回答
  •  庸人自扰
    2020-12-14 14:39

    See the excerpt from UIKit code documentation:

    /*
         New behavior on iOS 7.
         Default is YES.
         You may force an opaque background by setting the property to NO.
         If the navigation bar has a custom background image, the default is inferred 
         from the alpha values of the image—YES if it has any pixel with alpha < 1.0
         If you send setTranslucent:YES to a bar with an opaque custom background image
         it will apply a system opacity less than 1.0 to the image.
         If you send setTranslucent:NO to a bar with a translucent custom background image
         it will provide an opaque background for the image using the bar's barTintColor if defined, or black
         for UIBarStyleBlack or white for UIBarStyleDefault if barTintColor is nil.
         */
    

    Correct Swift 4 solution is

    UINavigationBar.appearance().isTranslucent = false
    UINavigationBar.appearance().backgroundColor = .white
    

提交回复
热议问题