Uisearchbar Out of Screen Bounds When Navigation Bar Translucent = False

Setting translucent to NO on UISearchBar

For UISearchBarStyleProminent:

1) Be sure to check the "Translucent" box for the search bar in the Attributes Inspector.

2) Add the following to viewDidLoad:

self.navigationController.navigationBar.translucent = NO; // If you have a navBar
self.searchDisplayController.searchBar.translucent = NO;

Edit From @RudolfAdamkovic:

"I've found that for UISearchBarStyleProminent, executing [the following] helps. That way, you can keep it on in Storyboard."

searchBar.translucent = YES;
searchBar.translucent = NO;

For UISearchBarStyleMinimal:

In order to get the minimal search bar to not be translucent I have put together a workaround.

1) Be sure to check the "Translucent" box for the search bar in the Attributes Inspector.

2) Add the following code to viewDidLoad:

self.navigationController.navigationBar.translucent = NO;
self.searchDisplayController.searchBar.translucent = NO;
self.searchDisplayController.searchBar.backgroundColor = [UIColor desiredColor];

3) A UIView needs to be added to the viewController. This view needs to be 20px heigh and should have the same color as the searchBar.barTintColor.

Note: I think this workaround is needed because: "The style UISearchBarStyleMinimal provides no default background color or image but will display one if customized as such." Thus the only way to get this functionality for UISearchBarStyleMinimal is to set the backgroundColor.

See UISearchBar documentation for more details.

iOS 9 searchBar disappears from table header view when UISearchController is active

It seems all of us got the same problem but they were solved in different ways. However none of the suggested answers worked for me :(. Nevertheless thank you all for your time.

I got a solution that solved my problem. It is setting Extend Edges - Under Opaque Bars of my (MyModalView: UITableViewController) to true in the Storyboard using Interface Builder.

In summary:

MyModalView: UITableViewController, in Storyboard using Interface Builder has

Extend Edges:
- Under Top Bars ticked
- Under Bottom Bars ticked
- Under Opaque Bars ticked

screenshot

UINavigationBar is white when it's bg color is set to black

change backgroundColor to barTintColor and

try this

UINavigationBar.appearance().barTintColor = UIColor.blackColor()
UINavigationBar.appearance().translucent = false

e.g

 func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool
{
UINavigationBar.appearance().barTintColor = UIColor.blackColor()
UINavigationBar.appearance().translucent = false

return true
}

or use

   self.navigationController!.navigationBar.barTintColor = UIColor.blackColor()
self.navigationController!.navigationBar.translucent = false

e.g

 override func viewDidLoad() {
super.viewDidLoad()

self.navigationController!.navigationBar.barTintColor = UIColor.blackColor()
self.navigationController!.navigationBar.translucent = false

}

Strange UISearchDisplayController view offset behavior in iOS 7 when embedded in navigation bar

I remember running into the same exact problem that you are observing.There could be a couple of solutions you can try.

  • If you are using storyboards
    You should click on the view controller or TableView Controller which you have set up for your tableview and go to its attribute inspector and look under ViewController section and set the Extend Edges section to be under Top Bars.

  • If you are not using storyboards you can manually set the settings using the viewcontrollers edgesForExtendedLayout property and that should do the trick. I was using storyboards.

remove black border from UISearchController search bar swift

Fixed this after a lot of search. Here's how i did it. In viewDidLoad, added the following lines:

self.searchController.searchBar.translucent = false
self.searchController.searchBar.backgroundImage = UIImage()
self.searchController.searchBar.barTintColor = UIColor.redColor()
self.searchController.searchBar.tintColor = UIColor.whiteColor()

After that in app.delegate file in didFinishLaunchingWithOptions added the following code:

let backgroundColor = UIColor.redColor()
let foregroundColor = UIColor.whiteColor()

UIApplication.sharedApplication().statusBarStyle = .LightContent

UINavigationBar.appearance().shadowImage = UIImage()

UINavigationBar.appearance().setBackgroundImage(backgroundColor.toImage(), forBarMetrics: UIBarMetrics.Default)

UINavigationBar.appearance().tintColor = foregroundColor

UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName: foregroundColor]

Also need this extension on the app.delegate file (place outside of the class)

extension UIColor{
func toImage() -> UIImage {
let rect = CGRectMake(0, 0, 1, 1)
UIGraphicsBeginImageContextWithOptions(rect.size, true, 0)
self.setFill()
UIRectFill(rect)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image
}
}

(Thanks to Noel for the extension taken from this answer)

And finally, the desired result:

Sample Image



Related Topics



Leave a reply



Submit