ios - How to hide iOS7 UINavigationBar 1px bottom line -


i have app needs navigation bar blend in content.

does know how rid of or change color of annoying little bar?

on image below situation have - i'm talking 1px height line below "root view controller"

enter image description here

to this, should set custom shadow image. shadow image shown need set custom background image, quote apple's documentation:

for custom shadow image shown, custom background image must set setbackgroundimage(_:for:) method. if default background image used, default shadow image used regardless of value of property.

so:

let navigationbar = navigationcontroller!.navigationbar navigationbar.setbackgroundimage(#imageliteral(resourcename: "barbackground"),                                                         for: .default) navigationbar.shadowimage = uiimage() 

above "official" way hide it. unfortunately, removes bar's translucency.

i don't want background image, color

you have options:

  1. solid color, no translucency:

    navigationbar.bartintcolor = uicolor.redcolor() navigationbar.istranslucent = false navigationbar.setbackgroundimage(uiimage(), for: .default) navigationbar.shadowimage = uiimage() 
  2. create small background image filled color , use it.

  3. use 'hacky' method described below. keep bar translucent.

how keep bar translucent?

to keep translucency need approach, looks hack works well. shadow we're trying remove hairline uiimageview somewhere under uinavigationbar. can find , hide/show when needed.

instructions below assume need hairline hidden in 1 controller of uinavigationcontroller hierarchy.

  1. declare instance variable:

    private var shadowimageview: uiimageview? 
  2. add method finds shadow (hairline) uiimageview:

    private func findshadowimage(under view: uiview) -> uiimageview? {     if view uiimageview && view.bounds.size.height <= 1 {         return (view as! uiimageview)     }      subview in view.subviews {         if let imageview = findshadowimage(under: subview) {             return imageview         }     }     return nil } 
  3. add/edit viewwillappear/viewwilldisappear methods:

    override func viewwillappear(_ animated: bool) {     super.viewwillappear(animated)      if shadowimageview == nil {         shadowimageview = findshadowimage(under: navigationcontroller!.navigationbar)     }     shadowimageview?.ishidden = true }  override func viewwilldisappear(_ animated: bool) {     super.viewwilldisappear(animated)      shadowimageview?.ishidden = false } 

the same method should work uisearchbar hairline, , (almost) else need hide :)

many @leo natan original idea!


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -