Need to get placeholder text of UITextField
Need to get placeholder text of UITextField
Is it possible to get the placeholder value of UITextField, which is designed in storyboard?
I need to validate the form which is having more textfields, so instead of giving static value, I want to give placeholder string of particular textfield as alert message.
Answer by Adam for Need to get placeholder text of UITextField
Use the placeholder
property:
textField.placeholder
Answer by Marcus Adams for Need to get placeholder text of UITextField
The UITextField
class has a placeholder
property. To reference the UITextField
in code, you'll need to create an outlet for it in your view controller.
If you named the outlet
myTextField
, you could reference the placeholder like this: let placeholder = self.myTextField.placeholder
Answer by Pavan Gandhi for Need to get placeholder text of UITextField
Its work ...
For getting placeholder text you need to wire up your textfield with its IBOutlet object like,
@IBOutlet var txtField : UITextField?
Now you set Placeholder Statically or dynamically
self.txtField!.attributedPlaceholder = NSAttributedString(string:"Good", attributes:[NSForegroundColorAttributeName: UIColor.grayColor()])
After that anywhere you can simply get its placeholder text and compare or validate ur textfield like
if((self.txtField!.placeholder! as NSString).isEqualToString("Good")) { // Do here Whatever you want } else if(self.txtField!.placeholder!.isEmpty == true) { // check its empty or not }
Answer by Jigar Tarsariya for Need to get placeholder text of UITextField
Simply write like below code,
if((self.myTextFiled!.placeholder! as NSString).isEqualToString("AnyString")) { // your code here }
Answer by user5724238 for Need to get placeholder text of UITextField
For placeholder first you should create IBOUTLET for textfield and then do:
if let str = textfiled.placeholder { if !str.isEmpty { //do something } }
Fatal error: Call to a member function getElementsByTagName() on a non-object in D:\XAMPP INSTALLASTION\xampp\htdocs\endunpratama9i\www-stackoverflow-info-proses.php on line 72
0 comments:
Post a Comment