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);
    }
  • 相关阅读:
    Swift
    Swift
    第二章_session管理
    HDU-1387-Team Queue
    Install Orace 11g on Solaris 10 Sparc 64 bit
    Linux 多学习过程
    dispatch_once认识分析
    关于包围神经猫的想法实现
    嵌入在网站上Flash播放机(2)
    初学者应学会如何加快seo
  • 原文地址:https://www.cnblogs.com/firstrate/p/7888104.html
Copyright © 2011-2022 走看看