UI第2课UILable

UILable能嵌套使用,第二层的Lable2的坐标是第一层的相对坐标,即

 UILabel *label = [[UILabelallocinitWithFrame:CGRectMake(0,2020050)];

 UILabel *label1 = [[UILabelallocinitWithFrame:CGRectMake(0,020050)];

[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];



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值