首页 > 代码库 > [iOS基础控件 - 3.1] QQ登陆界面
[iOS基础控件 - 3.1] QQ登陆界面
A.storyboard 控件版
1.label
2.textfield
a.Keyboard Type
账号:Number Pad
密码:Number and Punctuation
b.Placeholder:提示文字
c.Clear Button: Appears with editing 清除按钮
d.Secure Text Entry:密码格式输入
3.button
1 @interface ViewController () 2 @property (weak, nonatomic) IBOutlet UITextField *qqField; 3 @property (weak, nonatomic) IBOutlet UITextField *pwdField; 4 5 - (IBAction)login; 6 7 @end 8 9 @implementation ViewController10 11 - (void)viewDidLoad {12 [super viewDidLoad];13 // Do any additional setup after loading the view, typically from a nib.14 }15 16 - (void)didReceiveMemoryWarning {17 [super didReceiveMemoryWarning];18 // Dispose of any resources that can be recreated.19 }20 21 - (IBAction)login {22 NSLog(@"%@ - %@", self.qqField.text, self.pwdField.text);23 }24 @end
B.通过代码创建按钮
1 @interface ViewController () 2 3 - (void) addLabel; 4 - (void) addTextField; 5 - (void) addLoginButton; 6 - (void) login; 7 8 @end 9 10 @implementation ViewController11 12 - (void)viewDidLoad {13 [super viewDidLoad];14 // Do any additional setup after loading the view, typically from a nib.15 16 [self addLabel];17 [self addTextField];18 [self addLoginButton];19 }20 21 - (void)didReceiveMemoryWarning {22 [super didReceiveMemoryWarning];23 // Dispose of any resources that can be recreated.24 }25 26 - (void) addLabel {27 UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 45, self.view.frame.size.width, 21)];28 [titleLabel setTextAlignment:NSTextAlignmentCenter];29 titleLabel.text = @"QQ登陆界面2";30 [self.view addSubview:titleLabel];31 32 UILabel *qqLabel = [[UILabel alloc] initWithFrame:CGRectMake(60, 91, 26, 21)];33 qqLabel.text = @"QQ";34 [self.view addSubview:qqLabel];35 36 UILabel *pwdLabel = [[UILabel alloc] initWithFrame:CGRectMake(60, 131, 34, 21)];37 pwdLabel.text = @"密码";38 [self.view addSubview:pwdLabel];39 }40 41 - (void) addTextField {42 UITextField *qqField = [[UITextField alloc] initWithFrame:CGRectMake(109, 87, 151, 30)];43 qqField.placeholder = @"请输入QQ账号";44 [qqField setClearButtonMode:UITextFieldViewModeWhileEditing];45 [qqField setKeyboardType:UIKeyboardTypeNumberPad];46 [qqField setBorderStyle:UITextBorderStyleRoundedRect];47 [qqField setTag:1];48 [self.view addSubview:qqField];49 50 UITextField *pwdField = [[UITextField alloc] initWithFrame:CGRectMake(109, 127, 151, 30)];51 pwdField.placeholder = @"请输入QQ密码";52 [pwdField setSecureTextEntry:YES];53 [pwdField setKeyboardType:UIKeyboardTypeNumbersAndPunctuation];54 [pwdField setClearButtonMode:UITextFieldViewModeWhileEditing];55 [pwdField setBorderStyle:UITextBorderStyleRoundedRect];56 [pwdField setTag:2];57 [self.view addSubview:pwdField];58 }59 60 - (void) addLoginButton {61 // 注意如果使用UIButtonTypeCustom,默认背景色和titleColor都是是白色,显示不出来62 UIButton *loginButton = [UIButton buttonWithType:UIButtonTypeSystem];63 64 CGRect loginRect = CGRectMake(145, 177, 30, 30);65 loginButton.frame = loginRect;66 [loginButton setTitle:@"登陆" forState:UIControlStateNormal];67 [loginButton addTarget:self action:@selector(login) forControlEvents:UIControlEventTouchUpInside];68 69 [self.view addSubview:loginButton];70 }71 72 #pragma mark - action73 - (void) login {74 UITextField *qqField = [self.view viewWithTag:1];75 UITextField *pwdField = [self.view viewWithTag:2];76 77 NSLog(@"登陆---->%@ - %@", qqField.text, pwdField.text);78 }79 @end
[iOS基础控件 - 3.1] QQ登陆界面
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。