UILable能嵌套使用,第二层的Lable2的坐标是第一层的相对坐标,即
UILabel *label
= [[UILabelalloc] initWithFrame:CGRectMake(0,20, 200, 50)];
UILabel *label1
= [[UILabelalloc] initWithFrame:CGRectMake(0,0, 200, 50)];
[label addsubView:label1];
AppDelegate.m
/*
UILabel:
*/
UILabel *label = [[UILabelalloc] initWithFrame:CGRectMake(0,20, 200, 50)];
//设置文字
label.text =@"wahaha";
label.backgroundColor = [UIColoryellowColor];
//设置字体
/*
UIFont:字体类
*/
//获取当前系统支持的字体名
NSArray *fontArr = [UIFontfamilyNames];
NSLog(@"fontArr is %@",fontArr);
//获取字体大小是30的字体对象
UIFont *font =[UIFontsystemFontOfSize:30];
//同事改变字体大小和字体名
font =[UIFontfontWithName:fontArr[11]size:20];
//改变label上的字体
label.font = font;
label.textColor = [UIColororangeColor];
[self.windowaddSubview:label];
[labelrelease];
UILabel *label1 = [[UILabelalloc] initWithFrame:CGRectMake(0,80, 200, 30)];
label1.text =@"123456";
//设置文本对齐方式
/*
NSTextAlignmentLeft 左对齐
NSTextAlignmentCenter 居中
NSTextAlignmentRight 右对齐
*/
label1.textAlignment =NSTextAlignmentCenter ;
//给文字设置阴影颜色
label1.shadowColor = [UIColororangeColor];
//阴影偏移
label1.shadowOffset =CGSizeMake(-1, -1);
[self.windowaddSubview:label1];
[label1release];
//圆角边阴影空间
//导入QuartzCore.framework框架
UILabel *label2 = [[UILabelalloc] initWithFrame:CGRectMake(0,140, 200, 30)];
label2.text =@"df sadsfdsafsda dddddddddas ";
label2.backgroundColor = [UIColorgrayColor];
//圆角
label2.layer.cornerRadius =10.0;
//边框颜色将UIColor转化为CGColorRed
label2.layer.borderColor =[UIColorblackColor].CGColor;
//设置边框的线宽
label2.layer.borderWidth =2.0;
// //控件边框带阴影效果(有问题)
// label2.layer.shadowOpacity =1.0;
// label2.layer.shadowColor =[UIColor blackColor].CGColor;
// label2.layer.shadowOffset = CGSizeMake(10, 19);
//设置折行方式
label2.lineBreakMode =NSLineBreakByCharWrapping;
//当文字很长时,应该让文字大小自适应控件宽度(不常用)
label2.adjustsFontSizeToFitWidth =YES;
[self.windowaddSubview:label2];
[label2release];
UILabel *label3 = [[UILabelalloc] initWithFrame:CGRectMake(0,180, 300, 300)];
//设置label的行数
//为0自动折为N行(前提是Frame高度要够)
label3.numberOfLines =0;
label3.text =@"dfasdsafsdafsdasdagsadgdsafsdagsadgfdgfdgdfsgsdfgsd";
[self.windowaddSubview:label3];
[label3release];