Ios 是否在swift中禁用UITextField中的闪烁光标?

Ios 是否在swift中禁用UITextField中的闪烁光标?,ios,swift,uitextfield,swift3,Ios,Swift,Uitextfield,Swift3,如何从UITextField禁用Swift中的光标?条件-当用户登录时,然后进入应用程序。如果用户可以从应用程序注销,则不会将光标显示在UITextField中。首先在用户默认值中设置一些布尔值,当用户按下注销按钮时,将该值设置为否 例如 UserDefaults.standard().set(true, forKey: "disalert") 当你来到这一页时,检查如下条件 let disalert: Bool = UserDefaults.standard().bool(forKey: "

如何从
UITextField
禁用Swift中的光标?条件-当用户登录时,然后进入应用程序。如果用户可以从应用程序注销,则不会将光标显示在UITextField中。

首先在
用户默认值中设置一些布尔值,当用户按下注销按钮时,将该值设置为

例如

UserDefaults.standard().set(true, forKey: "disalert")
当你来到这一页时,检查如下条件

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

      self.youtextField().tintColor = UIColor.blueColor()
    if disalert {
        self.youtextField().tintColor = UIColor.clearColor()
        self.youtextField().resignFirstresponder()
     }
当用户按下登录按钮时,将用户默认值设置为

UserDefaults.standard().set(false, forKey: "disalert")

(self.youtextField.valueForKey("textInputTraits") as! String)["insertionPointColor"] = UIColor.clearColor()
或者像

 self.youtextField().tintColor = UIColor.clearColor()

如果您只是不想使用
光标
,则可以将其设置为
tintColor
clearColor
。在这种情况下,您的文本字段将处于活动状态。如果要将其设为非活动字段,则应调用
辞职第一响应者
方法
文本字段

首先,您需要确认UITextFieldDelegate,然后将您的textField设置为
yourTextField.delegate=self
添加
yourTextField.resignFirstResponder()

到您的代码。将resignFirstResponder呼叫到您的文本字段。 您也可以使用下面的代码(根据您的需要)

在委托方法
textfielddendediting(textField:UITextField)
中,检查(if)它是否有一些值/text为not


yourTextField.attributedPlaceholder=NSAttributeString(字符串:“用户名”,属性:[NSForegroundColorAttributeName:UIColor.whiteColor()])textUserName.resignFirstResponder()

适用于我的Swift 4:

textField.tintColor = UIColor.clear

你可以改变颜色

self.youtextField().tintColor=UIColor.clearColor()


您为文本字段创建了一个类

simple将当前文本字段的色调更改为
tintColor=[UIColor clearColor]
您确认UITextFieldDelegate了吗?self.youtextField().tintColor=UIColor.clearColor()为meThis工作应该是选定的答案。