標籤:
(如果需要的不是使用的屬性值如換行形式,可以把對應的屬性在程式中書寫然後按"command"+滑鼠左鍵點擊就可以查看所有屬性值)
一label基本設定
self.view.backgroundColor = [UIColor redColor];
//建立第一個標籤控制項
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(50, 50, 200, 30)];
//對位置設定
//對控制項的中心點進行設定
label.center = self.view.center;
label.frame = CGRectMake(20, 20, 30, 30);
//顯示文字
label.text = @"我是美女";
//設定字型大小
label.font = [UIFont systemFontOfSize:30];
//自適應大小的方法 標籤的大小由字型的大小長度決定
[label sizeToFit];
//字型的顏色 alpha 透明度 0 - 1 0- 1
label.textColor = [UIColor colorWithRed:0/255.0 green:0/255.0 blue:195/255.0 alpha:1];
//Red Green Blue 0 - 255 255 255 255
// 0 - 1
//字型對齊格式 右側是枚舉類型
label.textAlignment = NSTextAlignmentCenter;
//加背景顏色
label.backgroundColor = [UIColor greenColor];
//顯示出來 將標籤 放到視圖上 進行顯示
[self.view addSubview:label];
//addSubview 添加子視圖
//不是程式崩潰前提下 問題:
//第一點 frame是否設定了
//第二點 是不是加到了父視圖中
//第三點 背景色和 控制項顏色 一樣
二.文字自適應
//建立label
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 50, 200, 999)];
label.backgroundColor = [UIColor greenColor];
label.text = @"To be or not to be, that is a question。To be or not to be, that is a question。To be or not to be, that is a question。To be or not to be, that is a question。To be or not to be, that is a question。";
label.font = [UIFont systemFontOfSize:18];
label.textColor = [UIColor redColor];
//設定 label的換行模式
label.lineBreakMode = NSLineBreakByWordWrapping; //根據單詞進行換行
//設定label顯示幾行 可以有無限行
label.numberOfLines = 0;
[label sizeToFit];
[self.view addSubview:label];
iosiOSlabel基本使用以及文字自適應