[iOS基础控件 - 3.1] QQ登陆界面
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 ViewController 10 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
1 @interface ViewController () 2 3 - (void) addLabel; 4 - (void) addTextField; 5 - (void) addLoginButton; 6 - (void) login; 7 8 @end 9 10 @implementation ViewController 11 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 - action 73 - (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
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。