美文网首页iOS开发进阶iOS DeveloperiOS技术资料
利用NSMutableAttributedString实现lab

利用NSMutableAttributedString实现lab

作者: 骑马纵天下 | 来源:发表于2017-06-02 16:23 被阅读91次

    UILabel*label = [[UILabelalloc]initWithFrame:CGRectMake(0,0,self.frame.size.width,self.frame.size.height)];

    //使用斜杠n是字体显示为两行

    label.text=@"随堂测验\n(学习完成后,开始测试)";

    label.font=  [UIFontsystemFontOfSize:10];

    //使用换行符号切莫忘记写这句

    label.numberOfLines=0;

    label.textColor= [UIColorhexChangeFloat:@"A5A5A5"];

    //利用属性字符串修改字体大小颜色

    NSMutableAttributedString*AttributedStr = [[NSMutableAttributedStringalloc]initWithString:label.text];

    [AttributedStraddAttribute:NSForegroundColorAttributeName

    value:[HuConfigrationuiColorFromString:@"#D3D3D3"]

    range:NSMakeRange(0,4)];

    [AttributedStraddAttribute:NSFontAttributeName

    value:[UIFontcustomFontSize:18]

    range:NSMakeRange(0,4)];

    //修改行间距

    NSMutableParagraphStyle*paragraphStyle = [[NSMutableParagraphStylealloc]init];

    [paragraphStylesetLineSpacing:4];

    [AttributedStraddAttribute:NSParagraphStyleAttributeName

    value:paragraphStyle

    range:NSMakeRange(0, [label.textlength])];

    label.attributedText= AttributedStr;

    label.textAlignment=NSTextAlignmentCenter;

    [selfaddSubview:label];

    效果图:

    相关文章

      网友评论

        本文标题:利用NSMutableAttributedString实现lab

        本文链接:https://www.haomeiwen.com/subject/skyufxtx.html