如何在UITextField中添加占位符?

时间:2015-07-16 09:00:13

标签: objective-c

- (IBAction)segueBut:(id)sender {
    if(_textField.text.length>0&& _textField1.text.length>0 && [_textField1.text isEqual:@"zeeshan"])
    {
        NSString *textoftextfield=_textField.text;
        [ [NSUserDefaults standardUserDefaults] setObject:textoftextfield forKey:@"Name"];
        NSString *textoftextfield1=_textField1.text;
        [ [NSUserDefaults standardUserDefaults] setObject:textoftextfield1 forKey:@"Password"];
        [self performSegueWithIdentifier:@"segueidentifier" sender:self];
    }
    else
    {
        UIAlertView *alert= [[UIAlertView alloc]initWithTitle:@"Error" message:@"Insert Username and password Textfield is empty"   delegate:nil cancelButtonTitle:@"cancel" otherButtonTitles:@"OK", nil];
        alert.delegate=self;
        [alert show];
    }
}

2 个答案:

答案 0 :(得分:1)

使用文本字段的属性占位符并传递字符串。

node_modules

答案 1 :(得分:0)

语法糖方式:

_textField.placeholder = @"your text here";

或正常方式:

[_textField setPlaceholder:@"your text here"];