当前位置:首页 > 通信资讯 > 正文

ios中swift uisearchcontrol(ios中swift uisearchcontrol)

创建一个uisearchcontroller

如果传入的searchresultscontroller为nil,则表示搜索的结果在当前控制器中显示,现在我让它在searchresultvc中显示

?
1 2 3 4 5 6 7 8 9 10 11 12 13 // 创建searchresultvc let searchresultvc = uiviewcontroller() // 设置背景颜色为红色 searchresultvc.view.backgroundcolor = uicolor.red let searchcontroller = uisearchcontroller(searchresultscontroller: searchresultvc) // 设置背景颜色 searchcontroller.view.backgroundcolor = uicolor (red: 0.97, green: 0.97, blue: 0.97, alpha: 1.0) // 默认为yes,设置开始搜索时背景显示与否 // searchcontroller.dimsbackgroundduringpresentation = false // 默认为yes,控制搜索时,是否隐藏导航栏 // searchcontroller.hidesnavigationbarduringpresentation = false // 将搜索框视图设置为tableview的tableheaderview tableview.tableheaderview = searchcontroller.searchbar

ios中swift uisearchcontrol(ios中swift uisearchcontrol)

添加searchbar

设置搜索框

?
1 2 3 4 5 6 7 8 // 搜索框 let bar = searchcontroller.searchbar // 样式 bar.barstyle = .default // 设置光标及取消按钮的颜色 bar.tintcolor = rgba(r: 0.12, g: 0.74, b: 0.13, a: 1.00) // 设置代理 bar.delegate = self

ios中swift uisearchcontrol(ios中swift uisearchcontrol)

设置光标及取消按钮的颜色

去除背景

?
1 2 // 去除背景及上下两条横线 bar.setbackgroundimage(uiimage(), for: .any, barmetrics: .default)

ios中swift uisearchcontrol(ios中swift uisearchcontrol)

去除背景及上下两条横线

添加右侧语音按钮

?
1 2 3 4 5 6 7 8 9 10 // 右侧语音 bar.showsbookmarkbutton = true bar.setimage(#imageliteral(resourcename: "voicesearchstartbtn"), for: .bookmark, state: .normal) 监听语音按钮的点击 // mark:- uisearchbardelegate extension lxfcontactviewcontroller: uisearchbardelegate { func searchbarbookmarkbuttonclicked(_ searchbar: uisearchbar) { lxflog("点击了语音按钮") } }

ios中swift uisearchcontrol(ios中swift uisearchcontrol)

右侧语音效果

ios中swift uisearchcontrol(ios中swift uisearchcontrol)

以上所述是小编给大家介绍的ios中swift uisearchcontroller仿微信搜索框,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对服务器之家网站的支持!

原文链接:http://www.jianshu.com/p/6515e2dd52b5
如果您对该产品感兴趣,请填写办理(客服微信:xiaoxiongyidong)

为您推荐:

发表评论

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。