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

本小妞迷上赌 提交于 2019-12-05 05:40:38

问题


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? How to change search icons(magnifier and X icon) or could I change just colors?

Sorry for links but I cannot insert images here.


回答1:


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)



回答2:


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



来源:https://stackoverflow.com/questions/31413127/how-to-change-border-and-icons-in-search-bar-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!