iOS开发资源ui问题iOS进阶指南

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

2015-12-06  本文已影响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

上一篇下一篇

猜你喜欢

热点阅读