如何更改搜索栏中的边框和图标(Swift) [英] How to change border and icons in Search bar (Swift)

查看:129
本文介绍了如何更改搜索栏中的边框和图标(Swift)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个:

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

我需要这个

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

我必须创建边框或按图像设置?
如何更改搜索图标(放大镜和X图标)或者我可以只更改颜色吗?

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.

推荐答案

要添加边框,请使用视图 layer 属性。

To add borders use the views layer property.

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

如果要将角半径添加到searchBar:

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

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

要更改searchIcon,请在搜索栏上调用以下方法:

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

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

更改十字架:

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

这篇关于如何更改搜索栏中的边框和图标(Swift)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆