For your first problem, you could access the UITextField
of your UISearchbar
and edit the placeholder color:
var textfield:UITextField = searchBar.valueForKey("searchField") as UITextField
//Set the foregroundcolor of the placeholder
var attributedString = NSAttributedString(string: "your placeholdertext", attributes: [NSForegroundColorAttributeName : UIColor.whiteColor()])
textfield.attributedPlaceholder = attributedString
Then to also set the glass-color you have to access the leftView
of your UITextField
:
//Get the glass icon
var iconView:UIImageView = textfield.leftView as UIImageView
//Make the icon to a template which you can edit
iconView.image = iconView.image?.imageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate)
//Set the color of the icon
iconView.tintColor = UIColor.whiteColor()
To hide the cancel-button in your UISearchbar
you can use the searchBarShouldBeginEditing
delegate method and hide it. Just make sure to add the UISearchBarDelegate
first and set the delegate to your searchbar:
class YourviewController:UIViewController, UISearchBarDelegate{
override func viewDidLoad() {
searchbar.delegate = self
}
func searchBarShouldBeginEditing(searchBar: UISearchBar) -> Bool {
searchBar.setShowsCancelButton(false, animated: true)
return true
}
}