UILabel的使用
UILabel *labName = [[UILabel alloc] initWithFrame:CGRectMake(20, 70, 70, 40)];
labName.text = @"用户名:";
labName.font = [UIFont systemFontOfSize:14];
labName.textAlignment = NSTextAlignmentRight;
labName.backgroundColor = [UIColor redColor];
labName.textColor = [UIColor whiteColor];
[self.view addSubview:labName];
UITextField的使用
UITextField *tfName = [[UITextField alloc] initWithFrame:CGRectMake(110, 70, self.view.frame.size.width-150, 40)];
tfName.placeholder = @" 请输入用户名 ";
tfName.layer.borderWidth = 1;
tfName.layer.borderColor = [UIColor purpleColor].CGColor;
tfName.layer.cornerRadius = 10;
tfName.clearButtonMode = UITextFieldViewModeAlways;
tfName.keyboardType = UIKeyboardTypePhonePad;
tfName.returnKeyType = UIReturnKeyDone;
[self.view addSubview:tfName];
delegate的使用,这个是关于键盘上右下角按钮键功能的操作。下面是点击done按钮键盘消失的操作。
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
[textField resignFirstResponder];
return YES;
}
UIButton的使用
UIButton *btnTest = [UIButton new];
[btnTest setTitle:@"登录按钮" forState:UIControlStateNormal];
btnTest.frame = CGRectMake(30, 220, self.view.frame.size.width-60, 50);
btnTest.backgroundColor = [UIColor lightGrayColor];
btnTest.layer.borderWidth = 2;
btnTest.layer.borderColor = [UIColor blackColor].CGColor;
btnTest.layer.cornerRadius = 20;
[btnTest addTarget:self action:@selector(btnclickChange) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btnTest];
按钮定义的点击事件
-(void)btnclickChange{
MainVC *mainvc = [MainVC new];
[self.navigationController pushViewController:mainvc animated:YES];
}
UIImageView的使用
UIImageView *imgBg = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
imgBg.image = [UIImage imageNamed:@"imgBg"];
[self.view addSubview:imgBg];