Can the height of the UISearchbar TextField be modified?

后端 未结 8 884
-上瘾入骨i
-上瘾入骨i 2020-12-05 04:34

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

8条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-05 04:43

    I've found the accepted answer to be buggy at times.
    This is how i've solved the issue of having a custom height for the searchBar: I have set a colour image with the size I want and added it to the searchBar's textField in viewDidLoad:

    let image = getImageWithColor(UIColor.whiteColor(), size: CGSizeMake(600, 60))
    searchBar.setSearchFieldBackgroundImage(image, forState: .Normal)
    

    Followed with this func taken from here

    func getImageWithColor(color: UIColor, size: CGSize) -> UIImage {
        var rect = CGRectMake(0, 0, size.width, size.height)
        UIGraphicsBeginImageContextWithOptions(size, false, 0)
        color.setFill()
        UIRectFill(rect)
        var image: UIImage = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        return image
    }
    

提交回复
热议问题