1 - (void)viewDidLoad {
2 [super viewDidLoad];
3
4 UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 50, 55, 30)];
5 label.text = @"用户名";//设置内容
6 label.backgroundColor = [UIColor grayColor];//设置控件背景色
7 label.textColor = [UIColor whiteColor];//设置文字颜色
8 //设置label圆角
9 label.layer.cornerRadius = 5.0f;
10 label.layer.masksToBounds = YES;
11
12 [self.view addSubview:label];//将控件添加到视图
13
14
15 UITextField *textf = [[UITextField alloc] initWithFrame:CGRectMake(10, 100, 300, 44)];//初始化控件
16 textf.placeholder = @"请输入用户名";//设置提示内容
17 textf.font = [UIFont systemFontOfSize:16];//设置字体大小
18 textf.textColor = [UIColor whiteColor]; //设置文字颜色
19 textf.backgroundColor = [UIColor greenColor];//设置控件背景色
20 //设置label圆角
21 textf.layer.cornerRadius = 5.0f;
22 textf.layer.masksToBounds = YES;
23
24 [self.view addSubview:textf];//将控件添加到视图
25
26 }