Search code examples
iosuiviewuinavigationcontrolleruinavigationbaruinavigationitem

what is the secret of eliminating black string between UINavigationbar and another view by using following method?


i have UINavigationbar and view underneath it.enter image description here

and when i am saying following instructions the string is disappeared

   UINavigationBar.appearance().shadowImage = UIImage()
   UINavigationBar.appearance().setBackgroundImage( UIImage(), for: 
  .default)

why?


Solution

  • Per the documentation it looks like once you set setBackgroundImage it overrides the shadowImage with your custom implementation. On the navigation bar check out shadowImage it says:

    "/* Default is nil. When non-nil, a custom shadow image to show instead of the default shadow image. For a custom shadow to be shown, a custom background image must also be set with -setBackgroundImage:forBarMetrics: (if the default background image is used, the default shadow image will be used). */

    @property(nullable, nonatomic,strong) UIImage *shadowImage NS_AVAILABLE_IOS(6_0) UI_APPEARANCE_SELECTOR;"

    So you are overriding the default with a blank image which in turns removes the default shadow or string as you call it.