资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

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://cdkjz.cn/article/gddgcj.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220