title: Custom SearchBar iOS
body: <p>I am trying to create a Custom SearchBar so that I can </p>
  
  <ol>
  <li>Left Align the search image</li>
  <li>Change the corners of textbook to be a little more rounded.</li>
  <li>After the image is left aligned, the placeholder text can also be left aligned</li>
  <li>Change color of the search text</li>
  </ol>
  
  <p>However, even after subclassing <code>UISearchBar</code> I am unable to achieve what I want and facing following problems:</p>
  
  <ul>
  <li><p>When debugging, I can see UISearchBar in the view &amp; searchField inside it, but upon iteration on <code>self.subViews</code> and checking if the element is <code>UITextField</code>, I don't get anything. Re-checked and I always get one subView which has different memory address than that of searchbar in debug mode</p>
  
  <pre><code>var 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()
  }
  </code></pre></li>
  <li><p>I don't want to use undocumented ways and have almost tried all the ways I could find here, without any success</p></li>
  </ul>
  
  <p>Kindly help me. I am using Xcode 7 and iOS 8</p>