How to add a 1 pixel gray border around a UISearchBar TextField

后端 未结 6 2380
攒了一身酷
攒了一身酷 2021-02-19 14:21

I\'m trying to figure out how to add a 1 pixel stroke gray border to my UISearchBar in my app. The Facebook Messenger app accomplishes this quite well. (see pic below).

6条回答
  •  梦谈多话
    2021-02-19 14:33

    Swift 3 version

    override func viewDidLoad() {
        super.viewDidLoad()
    
        for s in searchBar.subviews[0].subviews {
            if s is UITextField {
                s.layer.borderWidth = 1.0
                s.layer.borderColor = UIColor.gray.cgColor
            }
        }
    }
    

    To make it round you can use textField.layer.cornerRadius property

提交回复
热议问题