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);
    }
  • 相关阅读:
    [PHP] PHP1 与 CGI
    [PHP] Phalcon操作示范
    [Shell] swoole_timer_tick 与 crontab 实现定时任务和监控
    [PHP] Phalcon应用升级PHP7记录
    [GNU] 喝一杯咖啡, 写一写 Makefile
    [PHP] Xhprof 非侵入式使用指南
    [PHP]OOP两类写法的性能对比
    [OSI] 网络间通信流程
    [OSI] 网络7层模型的理解
    [Tools] Vim 插件管理
  • 原文地址:https://www.cnblogs.com/firstrate/p/7888104.html
Copyright © 2011-2022 走看看