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
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:
Related Topics
Calculate Distance Between My Location and a Mapkit Pin on Swift
How to Use a Custom Initializer on a Uitableviewcell
Swift, Google Map Fit Bound for All the Markers
Fbsdkcorekit.Framework/Fbsdkcorekit: No Matching Architecture in Universal Wrapper
Uiimage Aspect Fill When Using Drawinrect
How to Run a Task in Swift on a Particular Date-Time in Background Either Application Is on or Off
Simplest Way to Implement a "Read More" Button to Expand a Uitextview in iOS Swift 2
Change Ncwidgetdisplaymode Programmatically in iOS10 Widget
Custom Sequence for Swift Dictionary
How to Get the Correct Current Time in iOS
Embedding a Uitableview as a Container View Within a Uiviewcontroller
Firebase Dynamic Link Doesnt Work in Safari Swift
Swiftui Tabbedview Only Shows First Tab's Content
How to Use a Generic Class Without the Type Argument in Swift
Swift 1.2 and Parse: Issue with Retrieving Images to Populate Pfquerycollectionviewcontroller