- (void)LY_Display
{
UILabel *Label = [[UILabel alloc] initWithFrame:CGRectMake(60, 180, 60, 30)];
[self.view addSubview:Label];
Label.backgroundColor = [UIColor clearColor];
Label.text = @"密 码";
Label.font= [UIFont fontWithName:@"zapfino" size:(15.0f)]; //字体设置
UITextField *Text = [[UITextField alloc] initWithFrame:CGRectMake(143, 180, 80, 30) ];
[self.view addSubview:LY_Text];
Text.backgroundColor = [UIColor whiteColor];
[Text setBorderStyle:UITextBorderStyleLine]; //边框设置
Text.placeholder = @"password"; //默认显示的字
Text.font = [UIFont fontWithName:@"helvetica" size:12]; //字体和大小设置
Text.textColor = [UIColor redColor]; //设置字体的颜色
Text.clearButtonMode = UITextFieldViewModeWhileEditing; //清空功能x
Text.returnKeyType = UIReturnKeyDone; //键盘有done
Text.secureTextEntry = YES; //密码输入时
Text.delegate = self; //托管
}
委托事件
@protocol UITextFieldDelegate <NSObject>
@optional
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField; // 返回NO则不许编辑
- (void)textFieldDidBeginEditing:(UITextField *)textField; // became first responder
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField; // 返回YES允许结束并且resign first responder status. 返回NO不许编辑状态结束
- (void)textFieldDidEndEditing:(UITextField *)textField; // 上面返回YES后执行;上面返回NO时有可能强制执行(e.g. view removed from window)
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string; // 返回NO不改变
- (BOOL)textFieldShouldClear:(UITextField *)textField; // clear button事件,返回NO过滤之
- (BOOL)textFieldShouldReturn:(UITextField *)textField; // 'return' key事件.返回NO过滤之
@end