iOS给UILabel设置缩进、行距、字体颜色

直接看代码:

创新互联从2013年创立,先为顺庆等服务建站,顺庆等地企业,进行企业商务咨询服务。为顺庆企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。

    UILabel *label = [[UILabelalloc]initWithFrame:CGRectMake(10,70,300,200)];

    label.numberOfLines = 0;

    label.backgroundColor = [UIColorcolorWithRed:235/255.0green:235/255.0blue:235/255.0alpha:1];

    

//------

   NSMutableAttributedString *text = [[NSMutableAttributedStringalloc]initWithString:@"1321313123211273127318273819273817381738713712837173812731837128371297319737131719371273187328193721731793\n"];

    

   //设置字体颜色

    [textaddAttribute:NSForegroundColorAttributeNamevalue:[UIColorredColor]range:NSMakeRange(0, text.length)];

    

   //设置缩进、行距

   NSMutableParagraphStyle *style = [[NSMutableParagraphStylealloc]init];

    style.headIndent = 30;//缩进

    style.firstLineHeadIndent =0;

    style.lineSpacing = 10;//行距

    [textaddAttribute:NSParagraphStyleAttributeNamevalue:stylerange:NSMakeRange(0, text.length)];

//------

    

    

    

//------

   NSMutableAttributedString *text2 = [[NSMutableAttributedStringalloc]initWithString:@"eqeqeuqoeuquequeqeqwuequeqoueqowueqoueqoshfkahfksdafhkalhfkdshf"];

   //设置字体颜色

    [text2addAttribute:NSForegroundColorAttributeNamevalue:[UIColorblueColor]range:NSMakeRange(0, text2.length)];

    

   //设置缩进、行距

   NSMutableParagraphStyle *style2 = [[NSMutableParagraphStylealloc]init];

    style2.headIndent = 0;

    style2.firstLineHeadIndent =20;

    style2.lineSpacing = 5;

    [text2addAttribute:NSParagraphStyleAttributeNamevalue:style2range:NSMakeRange(0, text2.length)];

//------

    

    [textappendAttributedString:text2];

    

    label.attributedText = text;

    [self.view addSubview:label];



新闻标题:iOS给UILabel设置缩进、行距、字体颜色
网页地址:http://bzwzjz.com/article/gddgcj.html

其他资讯

Copyright © 2007-2020 广东宝晨空调科技有限公司 All Rights Reserved 粤ICP备2022107769号
友情链接: 网站建设开发 定制级高端网站建设 手机网站建设 网站建设 重庆电商网站建设 成都定制网站建设 外贸营销网站建设 企业网站设计 成都网站设计 成都网站建设 成都网站建设公司 上市集团网站建设 成都响应式网站建设 网站建设公司 网站建设 企业网站设计 成都响应式网站建设公司 高端网站设计推广 重庆网站制作 营销网站建设 成都网站建设 成都网站建设流程