在swift中禁止从UITextField闪烁光标?

Cha*_*Jee 13 uitextfield ios swift swift3

如何在Swift中禁用游标UITextField?条件 - 用户登录时,进入应用程序.如果用户可以从应用程序注销,则不将光标显示到UITextField.

Lio*_*ion 28

如果你只是不想cursor那么你可以设置它的tintColorclearColor.在这种情况下,textField将处于活动状态.如果你想使它成为非活动字段,那么你应该调用resignFirstresponder方法textfield!


小智 15

对于适用于我的Swift 4:

textField.tintColor = UIColor.clear
Run Code Online (Sandbox Code Playgroud)


Anb*_*hik 6

最初设置一些bool值user default,当用户按下注销按钮时将值设置为NO

例如

UserDefaults.standard().set(true, forKey: "disalert")
Run Code Online (Sandbox Code Playgroud)

什么时候你来到这个页面检查条件,如

let disalert: Bool = UserDefaults.standard().bool(forKey: "disalert")

      self.youtextField().tintColor = UIColor.blueColor()
    if disalert {
        self.youtextField().tintColor = UIColor.clearColor()
        self.youtextField().resignFirstresponder()
     }
Run Code Online (Sandbox Code Playgroud)

当用户按下登录按钮时,将用户默认值设置为

UserDefaults.standard().set(false, forKey: "disalert")
Run Code Online (Sandbox Code Playgroud)

用得像

(self.youtextField.valueForKey("textInputTraits") as! String)["insertionPointColor"] = UIColor.clearColor()
Run Code Online (Sandbox Code Playgroud)

或设置如

 self.youtextField().tintColor = UIColor.clearColor()
Run Code Online (Sandbox Code Playgroud)


Sah*_*ini 2

首先你需要确认 UITextFieldDelegate 然后设置你的 textField 像yourTextField.delegate =self 添加 yourTextField.resignFirstResponder()

到你的代码。向您的TextField 调用resignFirstResponder。您还可以使用下面的代码(根据您的需要)。

在委托方法中textFieldDidEndEditing(textField: UITextField)检查(如果)它是否具有某些值/文本。

yourTextField.attributedPlaceholder = NSAttributedString(string: "User Name", attributes: [NSForegroundColorAttributeName: UIColor.whiteColor()]) textUserName.resignFirstResponder()