一:UITextField
_messageText=[[UITextField alloc]init];
_messageText.borderStyle=UITextBorderStyleRoundedRect;
_messageText.placeholder=@"SSSS";
_messageText.font=[UIFont fontWithName:@"Arial" size:15.0f];
_messageImage=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"account-"]];
_messageText.leftView=_messageImage;
_messageText.leftViewMode=UITextFieldViewModeAlways;
_messageText.keyboardType=UIKeyboardTypeDefault;
//密碼隱藏
_messageText.secureTextEntry = YES;
_messageText.delegate=self;
[self.view addSubview:_messageText];
//點擊空白區(qū)域回收鍵盤,并且view回到初始狀態(tài)
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
[_messageText resignFirstResponder];
}
//點擊鍵盤Return建回收鍵盤,并且view回到初始狀態(tài)
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
[_messageText resignFirstResponder];
return YES;
}
二:UIButton
_loginButton=[[UIButton alloc]init];
_loginButton.backgroundColor=[UIColor colorWithRed:52/255.f green:138/255.f blue:76/255.f alpha:1.00];
[_loginButton setTitle:@"登錄" forState:UIControlStateNormal];
[_loginButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[_loginButton addTarget:self action:@selector(loginBut:) forControlEvents:UIControlEventTouchUpInside];
//button點擊事件,包括判斷用戶,密碼的輸入狀態(tài),以及彈窗
-(void)loginBut:(UIButton *)button{
if ([self.messageText.text compare:@""]==NSOrderedSame ||[self.passText.text compare:@""]==NSOrderedSame )
{
UIAlertView *alertV = [[UIAlertView alloc]initWithTitle:@"提示" message:@"用戶、密碼不能為空"? delegate:self cancelButtonTitle:@"確定" otherButtonTitles:nil, nil];
[alertV show];
}else if (self.messageText.text.length <4 || self.passText.text.length<6)
{
UIAlertView *alertV = [[UIAlertView alloc]initWithTitle:@"提示" message:@"用戶名密碼不匹配)"? delegate:self cancelButtonTitle:@"確定" otherButtonTitles:nil, nil];
[alertV show];
}
}
友情植入,喜歡的可以加個微博