I am trying to create a Custom SearchBar so that I can
- Left Align the search image
- Change the corners of textbook to be a little more rounded.
- After the image is left aligned, the placeholder text can also be left aligned
- Change color of the search text
However, even after subclassing UISearchBar
I am unable to achieve what I want and facing following problems:
When debugging, I can see UISearchBar in the view & searchField inside it, but upon iteration on
self.subViews
and checking if the element isUITextField
, I don't get anything. Re-checked and I always get one subView which has different memory address than that of searchbar in debug modevar customSearchBar:UISearchBar? var searchField:UITextField? var button:UIButton? override func layoutSubviews() { for subView in self.subviews { if (subView.isKindOfClass(UITextField)) { searchField = (subView as! UITextField) break } } if ((searchField) != nil) { searchField?.textColor = UIColor.redColor() //Testing if code works? } super.layoutSubviews() }
I don't want to use undocumented ways and have almost tried all the ways I could find here, without any success
Kindly help me. I am using Xcode 7 and iOS 8