iOS 简单使用富文本格式对一个字符串进行不同设置

来源:互联网 发布:网络约车平台 计划书 编辑:程序博客网 时间:2024/06/06 09:57

            NSMutableAttributedString *myText =  [[NSMutableAttributedStringalloc] initWithString:[NSStringstringWithFormat:@"%@ %@",titleText,priceText]];

            [myText beginEditing];

            [myText addAttribute:NSFontAttributeNamevalue:[UIFontsystemFontOfSize:16]range:NSMakeRange(0, titleText.length)];

            [myText addAttribute:NSForegroundColorAttributeNamevalue:[UIColordarkGrayColor] range:NSMakeRange(0, titleText.length)];

            [myText addAttribute:NSFontAttributeNamevalue:[UIFontsystemFontOfSize:30]range:NSMakeRange(titleText.length, myText.length-titleText.length)];

            [myText addAttribute:NSForegroundColorAttributeNamevalue:[UIColorredColor] range:NSMakeRange(titleText.length, myText.length-titleText.length)];

            [myText endEditing];

            moneyLabel.attributedText = myText;

0 0
原创粉丝点击