Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making UISearch bar Transparent in Swift 4

I ma trying to make search bar transparent in swift 4.

Here is my code

    let  searchBar = UISearchBar()
    searchBar.sizeToFit()
    searchBar.placeholder = "search
    searchBar.isTranslucent = true
    searchBar.barTintColor = UIColor.clear
    searchBar.backgroundColor = UIColor.clear
    self.tabBarController?.navigationItem.titleView = searchBar

It ia appears like this enter image description here

I want to implement search bar as in screenshot. Please can anyone suggest me on this.

enter image description here

like image 391
Kishor Avatar asked Dec 13 '22 18:12

Kishor


2 Answers

completely transparent all part of uisearchbar :

searchBar.setSearchFieldBackgroundImage(UIImage(), for: .normal)
searchBar.setBackgroundImage(UIImage(), for: .any, barMetrics: .default)
  • searchBar is an outlet of UISearchBar from storyBoard
like image 192
Hamid Reza Ansari Avatar answered Dec 29 '22 20:12

Hamid Reza Ansari


Try this code:

searchBar.setSearchFieldBackgroundImage(UIImage(), for: .normal)

or:

UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self]).backgroundColor = .clear
like image 28
Ilya Kharabet Avatar answered Dec 29 '22 22:12

Ilya Kharabet