菜鸟启航:UILabel基本操作

来源:互联网 发布:java hello world代码 编辑:程序博客网 时间:2024/05/24 04:00

UILabel 文本


    //样式定制

    label.text =@"hello world!";

    label.textColor = [UIColorredColor];

    label.textAlignment =NSTextAlignmentCenter;

    label.backgroundColor = [UIColorblueColor];

    label.font = [UIFontboldSystemFontOfSize:20];

    label.shadowOffset =CGSizeMake(10,10);

    label.shadowColor = [UIColoryellowColor];

    label.highlighted =YES;

    label.highlightedTextColor = [UIColorgreenColor];

    label.numberOfLines =0;

    label.baselineAdjustment =UIBaselineAdjustmentNone;

    label.lineBreakMode =NSLineBreakByCharWrapping;



    //创建一个Label

   UILabel * label = [[UILabelalloc] initWithFrame:CGRectMake(60,200, 200, 200)];

    //Label提供显示内容

    label.text =@"Yestory is history,and tomorrow is mystery,but taday is a gift,that's why it's call present";

    //Label显示到屏幕上。

    

    //Labelf

   //

    label.backgroundColor = [UIColorgreenColor];

    

    //修改Label的对齐模式

    label.textAlignment =NSTextAlignmentCenter;

    //靠左 NSTextAlignmentLeft

    //居中 NSTextAlignmentCenter

    //靠右 NSTextAlignmentRight

    

    label.font = [UIFontsystemFontOfSize:35];

//    label.font = [UIFont italicSystemFontOfSize:30];

//    label.font = [UIFont boldSystemFontOfSize:30];

//    label.font = [UIFont fontWithName:@"Party LET" size:40];

    

   NSArray * array = [UIFontfamilyNames];

   NSLog(@"%@",array);

    

    //限制最多显示的行数 默认值是 1

    label.numberOfLines =10;

    

    //换行模式

//    label.lineBreakMode = NSLineBreakByCharWrapping;

//    label.lineBreakMode = NSLineBreakByClipping;

//    label.lineBreakMode = NSLineBreakByTruncatingHead;

//      label.lineBreakMode = NSLineBreakByTruncatingMiddle;

      label.lineBreakMode =NSLineBreakByTruncatingTail;

    

//    NSLineBreakByCharWrapping 按字符截断

//    NSLineBreakByClipping 按单词换行从末尾裁剪最后一行

//    NSLineBreakByTruncatingHead 按单词换行,末尾一行从头开始删节

    

    label.textColor = [UIColorredColor];

    

    //给文字添加阴影效果

    

    label.shadowOffset =CGSizeMake(5,5);

    label.shadowColor = [UIColorblackColor];

    

    //标记不能赋值为0

    label.tag =10;

        //字体大小自适应内容

    label.adjustsFontSizeToFitWidth =YES;

    label.minimumScaleFactor =0.5;

    

    [self.viewaddSubview:label];


0 0
原创粉丝点击