ios – 无法更改搜索栏背景颜色

ios – 无法更改搜索栏背景颜色,第1张

概述我有一个搜索栏: let searchBar:UISearchBar = UISearchBar(frame: CGRectMake((searchView.frame.width - UIScreen.mainScreen().bounds.width / 1.6) / 2, 0, UIScreen.mainScreen().bounds.width / 1.6, 24)) 我想改变文字输入部分 我有一个搜索栏:

let searchbar:UISearchbar = UISearchbar(frame: CGRectMake((searchVIEw.frame.wIDth - UIScreen.mainScreen().bounds.wIDth / 1.6) / 2,UIScreen.mainScreen().bounds.wIDth / 1.6,24))

我想改变文字输入部分的背景颜色.为此,我尝试过:

searchbar.barTintcolor = UIcolor(red: 0/255,green: 74/255,blue: 103/255,Alpha: 1)searchbar.backgroundcolor = UIcolor.redcolor()

但这两种变体都不起作用.如何更改我的UISearchbar textinput部分的背景颜色以及我做错了什么?

解决方法 如果您只想在VIEwController中更改它并且不希望其他任何地方生效,那么请使用

for vIEw in searchbar.subvIEws {            for subvIEw in vIEw.subvIEws {                if subvIEw .isKindOfClass(UITextFIEld) {                    let textFIEld: UITextFIEld = subvIEw as! UITextFIEld                    textFIEld.backgroundcolor = UIcolor.redcolor()                }            }        }

但是如果你想让它在整个应用程序中进行更改并定位到iOS 9.0或更高版本,那么应该使用appearanceWhenContainedInInstancesOfClasses之类的

UITextFIEld.appearanceWhenContainedInInstancesOfClasses([UISearchbar.self]).backgroundcolor = UIcolor.redcolor()
总结

以上是内存溢出为你收集整理的ios – 无法更改搜索栏背景颜色全部内容,希望文章能够帮你解决ios – 无法更改搜索栏背景颜色所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1019791.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存