Reputation: 11
I know how to disable the standard copy, paste, cut... options in Swift when editing a UITextField
's / UITextView
's text but I don't know how to do this with a UISearchBar
. With a text field I would subclass UITextField
and override the canPerformAction()
method. But when subclassing UISearchBar
this does not work and I don't know how to address the searchBar's textField. Furthermore I would really like to know, how you could change the color of the little 'X' on the right site of the search bar's text field, which is responsible for deleting all the text in the text field.
Would be great if someone could help me with these two things. Thanks in advance.
Upvotes: 1
Views: 1135
Reputation: 56372
Your best bet to change the clear button color is to use a custom image by calling
setImage(_ iconImage: UIImage?, forSearchBarIcon icon: UISearchBarIcon, state state: UIControlState)
on the UISearchBar
.
As to disabling copy/paste on the UISearchBar
's text field, I don't think there is a way to do that. Even if you get access to the UITextField
instance contained in it, there's no way you'd be able to change the behaviour for that particular instance.
Upvotes: 1