teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

2

fix1

2017/10/10 04:07

投稿

gtime
gtime

スコア51

title CHANGED
File without changes
body CHANGED
@@ -20,4 +20,5 @@
20
20
  このコードを実行しても色が変わりません
21
21
  textFieldの_clearButtonの色を変えるにはどのようにすればいいのでしょうか?
22
22
  foo.backgroundColor = .red を設定すると背景は赤くなるので tintColor だけ正常に動作していないと思われます。
23
+ 環境はXcode9, Swift4, iOS11 です。
23
24
  ![イメージ説明](e20247c918107d3361d7d266471052aa.png)

1

fix

2017/10/10 04:06

投稿

gtime
gtime

スコア51

title CHANGED
File without changes
body CHANGED
@@ -1,11 +1,23 @@
1
1
  ```swift
2
+ import UIKit
3
+ class ViewController: UIViewController, UISearchBarDelegate {
4
+ @IBOutlet weak var searchBar: UISearchBar!
5
+ override func viewDidLoad() {
6
+ super.viewDidLoad()
7
+ let textField = searchBar.value(forKey: "_searchField") as! UITextField
2
- let foo = textField.value(forKey: "_clearButton") as! UIButton
8
+ let foo = textField.value(forKey: "_clearButton") as! UIButton
9
+ print(foo)
3
10
 
4
- foo.setImage(faa.imageView?.image?.withRenderingMode(.alwaysTemplate), for: .normal)
11
+ foo.setImage(foo.imageView?.image?.withRenderingMode(.alwaysTemplate), for: .normal)
5
- foo.setImage(faa.imageView?.image?.withRenderingMode(.alwaysTemplate), for: .highlighted)
12
+ foo.setImage(foo.imageView?.image?.withRenderingMode(.alwaysTemplate), for: .highlighted)
6
-
13
+ foo.backgroundColor = .red
7
14
  foo.tintColor = .red
15
+ }
16
+ }
17
+
18
+
8
19
  ```
9
-
10
20
  このコードを実行しても色が変わりません
11
- textFieldの_clearButtonの色を変えるにはどのようにすればいいのでしょうか?
21
+ textFieldの_clearButtonの色を変えるにはどのようにすればいいのでしょうか?
22
+ foo.backgroundColor = .red を設定すると背景は赤くなるので tintColor だけ正常に動作していないと思われます。
23
+ ![イメージ説明](e20247c918107d3361d7d266471052aa.png)