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);
    }
  • 相关阅读:
    安装chrome driver(14)
    爬虫-selenium实现验证码自动登录(14)
    爬虫-反爬与反反爬(12)
    爬虫-模拟登录(13)
    爬虫-GIL与线程同步问题(11)
    爬虫-多进程(10)
    爬取csdn的数据与解析存储(9)
    Exchange Server 2016邮件系统建设方案
    Exchange 2016高可用及容灾架构选型参考
    Installing Exchange 2016 on Windows Server 2016 Step by Step
  • 原文地址:https://www.cnblogs.com/firstrate/p/7888104.html
Copyright © 2011-2022 走看看