建立UIlabel標籤,設置屬性。ide
#pragma mark--UILabel函數
//1.建立控件字體
UILabel *label = [[UILabel alloc] init];spa
//2.設置大小orm
label.frame = CGRectMake(50, 100, 300, 40);事件
//3.設置背景顏色ip
label.backgroundColor = [UIColor yellowColor];get
//4.設置文本it
label.text = @"hello world";io
//5.設置文本居中
label.textAlignment = NSTextAlignmentCenter;
//6.設置字體顏色
label.textColor = [UIColor darkGrayColor];
//設置圓角
// label.layer.cornerRadius = 8;
//7.添加到控制器視圖上
[self.view addSubview:label];
模擬器運行效果圖:
textField建立與屬性設置:
//建立與位置設定
UITextField *textField = [[UITextField alloc]initWithFrame:CGRectMake(50, 200, 300, 44)];
//2.文本框樣式 必須設置(邊框)
// textField.borderStyle = UITextBorderStyleBezel;
//3.提示語句
textField.placeholder = @"請輸入我很是帥";
//4.設置文本框背景顏色
textField.backgroundColor = [UIColor whiteColor];
//設置文本框圓角
textField.layer.cornerRadius = 8;
//添加到視圖
[self.view addSubview:textField];
模擬器運行效果圖:
#pragma mark -- UIButton
//1.建立按鈕方法,使用便利構造
UIButton *sureBtn = [UIButton buttonWithType:UIButtonTypeSystem];
//2.設置按鈕位置與大小
sureBtn.frame = CGRectMake(150, 300, 100, 40);
//3.設置按鈕顏色
sureBtn.backgroundColor = [UIColor redColor];
//4.正常狀態下的標題顯示
[sureBtn setTitle:@"登陸" forState:UIControlStateNormal];
//5.設置按鈕文本的文本顏色
[sureBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
// //6.設置選中下的狀態與文本顏色
// [sureBtn setTitle:@"取消" forState:UIControlStateSelected];
// [sureBtn setTitleColor:[UIColor blackColor] forState:UIControlStateSelected];
//1.設置圓角的半徑
sureBtn.layer.cornerRadius = 8;
// sureBtn.layer.masksToBounds = YES;
sureBtn.clipsToBounds = YES;
//爲sureBtn添加點擊事件 (sureButtonPressed:)是點擊後執行的函數
[sureBtn addTarget:self action:@selector(sureButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
//添加到視圖
[self.view addSubview:sureBtn];
模擬器運行效果圖: