How to change border and icons in Search bar (Swift)

后端 未结 2 2051
庸人自扰
庸人自扰 2021-02-10 00:53

I have this:

http://postimg.org/image/ag29m3e7d/

and I need this

http://postimg.org/image/4bacislw5/

I have to create border or set it by image

相关标签:
2条回答
  • 2021-02-10 01:21

    To add borders use the views layer property.

    self.searchBar.layer.borderColor = UIColor.blueColor().CGColor
    self.searchBar.layer.borderWidth = 1
    

    If you want to add the corner radius to the searchBar:

    self.searchBar.layer.cornerRadius = 3.0
    self.searchBar.clipsToBounds = true
    

    To change the searchIcon call the following method on the searchbar:

    self.searchbar.setImage(image, icon: UISearchBarIcon. UISearchBarIcon.Search, state: UIControlState.Normal)
    

    To change the cross:

    self.searchbar.setImage(image, icon: UISearchBarIcon. UISearchBarIcon.Clear, state: UIControlState.Normal)
    
    0 讨论(0)
  • 2021-02-10 01:35

    For the border, select your UITextField in story board, then, in the attributes inspector, choose the border style.

    0 讨论(0)
提交回复
热议问题