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工作应该是选定的答案。