美文网首页iOS开发资源ui问题iOS进阶指南
iOS改变searchBar搜索栏placeholder的字体颜

iOS改变searchBar搜索栏placeholder的字体颜

作者: 麦克学会了摇滚 | 来源:发表于2015-12-06 13:50 被阅读3329次

如题所示,就是一个小tip,百度了很久都没答案,就在stackoverflow上找到了答案,方法有如下几种:

1.iOS5+ oc版:

[[UILabelappearanceWhenContainedIn:[UISearchBarclass],nil]setTextColor:[UIColorredColor]];

2.取出searcher里的textfield,再进行修改:

//取出textfield

UITextField*searchField=[searchBar valueForKey:@"_searchField"];

//改变searcher的textcolor

searchField.textColor=[UIColor redColor];

//改变placeholder的颜色

[searchField setValue:[UIColorblueColor]forKeyPath:@"_placeholderLabel.textColor"];

3.swift版

var  textFieldInsideSearchBar=searchBar.valueForKey("searchField")as?UITextField

textFieldInsideSearchBar?.textColor=UIColor.whiteColor()   

var  textFieldInsideSearchBarLabel=textFieldInsideSearchBar!.valueForKey("placeholderLabel")as?UILabel

textFieldInsideSearchBarLabel?.textColor=UIColor.whiteColor()

以上内容参考ios - UISearchBar change placeholder color - Stack Overflow

相关文章

网友评论

    本文标题:iOS改变searchBar搜索栏placeholder的字体颜

    本文链接:https://www.haomeiwen.com/subject/tsxehttx.html