美文网首页
ios开发--常用基本控件(截取登陆部分)

ios开发--常用基本控件(截取登陆部分)

作者: 爱爱爱爱爱丫头的程序猿 | 来源:发表于2016-06-23 17:57 被阅读36次

    一: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];

    //点击空白区域回收键盘,并且view回到初始状态

    -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{

    [_messageText resignFirstResponder];

    }

    //点击键盘Return建回收键盘,并且view回到初始状态

    - (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点击事件,包括判断用户,密码的输入状态,以及弹窗

    -(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];

    }

    }




    友情植入,喜欢的可以加个微博

    相关文章

      网友评论

          本文标题:ios开发--常用基本控件(截取登陆部分)

          本文链接:https://www.haomeiwen.com/subject/nwfodttx.html