UILable API
初始化一个窗口,边界即为整个屏幕的大小
self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
设置背景颜色
self.window.backgroundColor = [UIColor whiteColor];
初始化一个label CGRectMake 设置lebel的坐标与宽高
参数说明
1. x坐标
2. y坐标
3. 宽度
4. 高度
struct CGRect {
CGPoint origin;
CGSize size;
};
struct CGPoint {
CGFloat x;
CGFloat y;
};
struct CGSize {
CGFloat width;
CGFloat height;
};
CGReck是一个结构体,里边包含了两个结构体
UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(50, 50, 100, 30)];
设置label的内容
label.text = @"这是一个label";
设置label的字体
循环遍历系统所有的字体
NSArray * array = [UIFont familyNames];
for (NSString * string in array) {
NSArray * array2 = [UIFont fontNamesForFamilyName:string];
for (NSString * temp in array2) {
NSLog(@"%@",temp);
}
}
label.font = [UIFont fontWithName:@"Monle" size:30];
设置字体颜色
红绿蓝 和透明度 1为不透明,0 为透明
label.textColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
对其方式 默认是左对齐
NSTextAlignmentCenter
NSTextAlignmentLeft
NSTextAlignmentRight
label.textAlignment = NSTextAlignmentCenter;
label的背景颜色
label.backgroundColor = [UIColor blackColor];
阴影的颜色和偏移的位置
label.shadowColor = [UIColor greenColor];
参数说明
1. 正数的时候是右偏 负数的时候左偏
2. 正数的时候是上偏 负数的时候下偏
label.shadowOffset = CGSizeMake(-5, -5);
换行模式
1. NSLineBreakByTruncatingHead .....something
2. NSLineBreakByTruncatingTail something....something
3. NSLineBreakByTruncatingMiddle something....
label.lineBreakMode = NSLineBreakByTruncatingTail;
label显示的行数
1. 为0时,全部显示,有多大显示多大
2. 不为0时,显示指定的行数
label.numberOfLines = 10;
自适应行高
[label sizeToFit]
颜色高亮,一般不常用
label.highlighted = YES;
label.highlightedTextColor = [UIColor orangeColor];
设置好之后要加入到父view上显示出来
[self.window addSubview:label]
设置根视图控制器
self.window.rootViewController = [[UIViewController alloc]init];
[self.window makeKeyAndVisible];