@property(nonatomic,strong) UIImageView*bgImageView;//登录背景
@property(nonatomic,strong) UITextField*phoneNumField;//手机号输入框
@property(nonatomic,strong) UITextField*passwordField;//密码输入框
//背景图
_bgImageView = [[UIImageView alloc]initWithFrame:self.view.frame];
_bgImageView.userInteractionEnabled = YES;
_bgImageView.backgroundColor = [UIColor grayColor];
_bgImageView.image = [UIImage imageNamed:@""];
[self.view addSubview:_bgImageView];
//手机号输入框
_phoneNumField = [[UITextField alloc] initWithFrame:CGRectMake(0.0f, 80.0f, ScreenWidth, 50.0f)];
[_phoneNumField setBorderStyle:UITextBorderStyleNone]; //外框类型
_phoneNumField.placeholder = @"请输入账号"; //默认显示的字
_phoneNumField.backgroundColor = [UIColor whiteColor];
_phoneNumField.secureTextEntry = NO; //密码
_phoneNumField.autocorrectionType = UITextAutocorrectionTypeNo;
_phoneNumField.autocapitalizationType = UITextAutocapitalizationTypeNone;
_phoneNumField.returnKeyType = UIReturnKeyDone;
_phoneNumField.clearButtonMode = UITextFieldViewModeWhileEditing; //编辑时会出现个修改X
_phoneNumField.delegate = self;
[_bgImageView addSubview:_phoneNumField];
//手机号label
UILabel*phoneLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, 0, 80, 50)];
phoneLabel.text = @"账号";
phoneLabel.textAlignment = NSTextAlignmentLeft;
phoneLabel.textColor = [UIColor blackColor];
phoneLabel.font = [UIFont systemFontOfSize:13];
UIView*phoneLeftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 80, 50)];
phoneLeftView.backgroundColor = [UIColor redColor];
[phoneLeftView addSubview:phoneLabel];
_phoneNumField.leftViewMode=UITextFieldViewModeAlways;
_phoneNumField.leftView=phoneLeftView;
//发送验证码
UIButton*button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0, 0, 80, 50);
NSMutableAttributedString *content = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"发送验证码"]];
NSRange contentRange = {0,[content length]};
[content addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:contentRange];
[button setAttributedTitle:content forState:UIControlStateNormal];
button.titleLabel.font = [UIFont systemFontOfSize:13];
UIView*phoneRightView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 80, 50)];
phoneRightView.backgroundColor = [UIColor yellowColor];
[phoneRightView addSubview:button];
_phoneNumField.rightViewMode=UITextFieldViewModeAlways;
_phoneNumField.rightView=phoneRightView;
//密码输入框
_passwordField = [[UITextField alloc] initWithFrame:CGRectMake(0.0f, 130.5f, ScreenWidth, 50.0f)];
[_passwordField setBorderStyle:UITextBorderStyleNone]; //外框类型
_passwordField.placeholder = @"6-12位数字或字母"; //默认显示的字
_passwordField.backgroundColor = [UIColor whiteColor];
_passwordField.secureTextEntry = YES; //密码
_passwordField.autocorrectionType = UITextAutocorrectionTypeNo;
_passwordField.autocapitalizationType = UITextAutocapitalizationTypeNone;
_passwordField.returnKeyType = UIReturnKeyDone;
_passwordField.clearButtonMode = UITextFieldViewModeWhileEditing; //编辑时会出现个修改X
_passwordField.delegate = self;
[_bgImageView addSubview:_passwordField];
//登录密码label
UILabel*passwordLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, 0, 80, 50)];
passwordLabel.text = @"密码";
passwordLabel.textAlignment = NSTextAlignmentLeft;
passwordLabel.textColor = [UIColor blackColor];
passwordLabel.font = [UIFont systemFontOfSize:13];
UIView*passwordLeftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 80, 50)];
passwordLeftView.backgroundColor = [UIColor redColor];
[passwordLeftView addSubview:passwordLabel];
_passwordField.leftViewMode=UITextFieldViewModeAlways;
_passwordField.leftView=passwordLeftView;
UITextfield常用属性
最新推荐文章于 2022-09-22 14:40:45 发布