zoukankan      html  css  js  c++  java
  • 价格不同字体大小的富文本实现方式

    1 富文本 的实现效果
     
    20A0ADCD D687 4AC9 A1FC 423F0375EA61
     
    2 方法的封装
     
    - (void)makeValueStringChangeWithPrice:(NSString *)price unit:(NSString *)unit
    {
        NSString *str = [NSStringstringWithFormat:@"¥ %@元/%@",price,unit];
        _valueLabel.text = str;
       
        NSMutableString * subtitlelabelStr = [NSMutableStringstringWithFormat:@"¥ %@元/%@",price,unit];
        _valueLabel.text = subtitlelabelStr;
       
        NSMutableAttributedString *attributedString = [[NSMutableAttributedStringalloc] initWithString:_valueLabel.text];
       
        [attributedString setAttributes:@{NSForegroundColorAttributeName:NF_Color_C19,NSFontAttributeName:[UIFontsystemFontOfSize:Near_Final_Font_T2]
                                          }range:NSMakeRange(0, 2)];
        NSRange tmpRange = [[[attributedString string] lowercaseString] rangeOfString:@"元"];
        NSRange valueRange;
        valueRange.location = 2;
        valueRange.length = tmpRange.location-1;
        [attributedString addAttributes:@{NSForegroundColorAttributeName:NF_Color_C19,NSFontAttributeName:[UIFontsystemFontOfSize:Near_Final_Font_T5]}range:valueRange];
       
        NSRange unitRange;
        unitRange.location = tmpRange.location+1;
        unitRange.length = [_valueLabel.textlength]-unitRange.location;
        [attributedString setAttributes:@{NSForegroundColorAttributeName:NF_Color_C19,NSFontAttributeName:[UIFontsystemFontOfSize:Near_Final_Font_T2]}range:unitRange];
       
        NSMutableParagraphStyle *paragraph = [[NSMutableParagraphStylealloc] init];
        paragraph.alignment = NSTextAlignmentRight;
        [attributedString addAttribute:NSParagraphStyleAttributeNamevalue:paragraph range:NSMakeRange(0, [_valueLabel.textlength])];
       
        _valueLabel.attributedText = attributedString;
        _valueLabel.frame = CGRectMake(self.bounds.size.width-200-10, CGRectGetMinY(self.scoreLabel.frame)-10-_valueLabel.contentSize.height, 200, 16);
    }
  • 相关阅读:
    WCF学习笔记之宿主在IIS中
    WCF学习笔记之配置文件
    WCF学习笔记之自托管
    深入C#中的事件
    深入理解c#中的const 和readonly的区别滴呀;
    鼠标跟着键盘飞=====兼容代码
    offset系列,scroll系列
    无缝链接轮播图
    完整轮播图
    location对象
  • 原文地址:https://www.cnblogs.com/firstrate/p/7888104.html
Copyright © 2011-2022 走看看