2016-04-13 19 views
0

私のアプリで私はこのような探索を設定している:検索バーの色合いのカラー

searchBar.delegate = self 
searchBar.showsCancelButton = true 
searchBar.tintColor = UIColor.whiteColor() 
searchBar.spellCheckingType = .No 
searchBar.autocapitalizationType = .None 
searchBar.autocorrectionType = .No 
searchBar.returnKeyType = .Done 
searchBar.sizeToFit() 

let view: UIView = self.searchBar.subviews[0] as UIView 
    for subView: UIView in view.subviews { 
     if subView.isKindOfClass(UITextField){ 
     subView.tintColor = UIColor.greenColor() 
     } 
     } 

このコードの一部は、私のキャンセルボタンの白いテキストの色と私の検索フィールドの緑の色を設定します。

ご覧のとおり、カーソルは緑色になりますが、テキストの色は黒です。 私の間違いは何ですか?

if subView.isKindOfClass(UITextField){ 
     subView.tintColor = UIColor.greenColor() 
} 

変更するには:あなたが持っている

enter image description here

+0

私は緑 – Stack108

+0

にテキストの色を変更したいと思いますが、これを見るのhttp:// stackoverflow.com/questions/26284658/searchbar-how-to-change-text-color –

+0

これも参照してくださいhttp://stackoverflow.com/questions/28499701/how-can-i-chan ge-the-uisearchbar-search-text-color –

答えて

3

それはあなたを助けたら

if let textView = subView as? UITextField { 
     textView.tintColor = UIColor.greenColor() 
     textView.textColor = UIColor.greenColor() 
} 
+0

大変ありがとうございます:) – Stack108

+0

もしうまくいくなら、あなたはどうぞよろしくお願いします:D – SeanLintern88

関連する問題