Can the height of the UISearchbar TextField be modified?

后端 未结 8 904
-上瘾入骨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 05:07

    This is the correct Swift 4.0 answer on how to change the height of a UISearchBar:

      let image = getImageWithColor(color: UIColor.clear, size: CGSize(width: 1, height: 40))
      searchBar.setSearchFieldBackgroundImage(image, for: .normal)
    

    Using following method:

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

    Tested on 4th. June. 2018

提交回复
热议问题