I\'m testing out my UI and I find the search bar a little bit too narrow for my liking. I also want to make sure people with poorer vision or poorer manual dexterity have n
If you use :
func setSearchFieldBackgroundImage(backgroundImage: UIImage?, forState state: UIControlState)
The height of UISearchBar's UITextfield would be the same as the height of the Image.
You can drop in an Image,use it to customize UISearchBar's UITextfield height and backgroundImage.
Or you can use the function below to create a round corner UIImage:
func getImageWithColor(color: UIColor, size: CGSize) -> UIImage {
let rect = CGRectMake(0, 0, size.width, size.height)
let path = UIBezierPath(roundedRect: rect, cornerRadius: 5.0)
UIGraphicsBeginImageContextWithOptions(size, false, 0)
color.setFill()
path.fill()
let image: UIImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image
}
The Width of the UIImage is ignored.But to have a corner radius ,it's better bigger than 10.0.
The code would be look like this:
let image = self.getImageWithColor(UIColor.lightGrayColor(), size: CGSizeMake(20, 20))
searchBar.setSearchFieldBackgroundImage(image, forState: .Normal)