搜索栏色调颜色

Sta*_*108 0 tint ios searchbar swift

在我的应用中,我设置了如下搜索器:

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()
         }
      }
Run Code Online (Sandbox Code Playgroud)

此代码部分为我的“取消”按钮设置了白色文本颜色,为我的搜索字段设置了绿色。

如您所见,光标将为绿色,但文本颜色为黑色。我怎么了

在此处输入图片说明

Sea*_*ern 5

您在哪里:

 if subView.isKindOfClass(UITextField){
      subView.tintColor = UIColor.greenColor()
 }
Run Code Online (Sandbox Code Playgroud)

改成:

 if let textView = subView as? UITextField {
      textView.tintColor = UIColor.greenColor()
      textView.textColor = UIColor.greenColor()
 }
Run Code Online (Sandbox Code Playgroud)