NSMutableString 的使用例子

NSString * priceString = [dict objectForKey:@"exhibition"];

    float price = [priceString floatValue];

    

    // 搜索文字

    NSString * str = [NSString stringWithFormat:@"¥%.2f万",price];

    NSString *tempStr = @"\\d{1,}";

    

    NSMutableArray *results = [NSMutableArray array];

    NSRange searchRange = NSMakeRange(0, [str length]);

    NSRange range;

    NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:str];

    while ((range = [str rangeOfString:tempStr options:NSRegularExpressionSearch range:searchRange]).location != NSNotFound)

    {

        [results addObject:[NSValue valueWithRange:range]];

        searchRange = NSMakeRange(NSMaxRange(range), [str length] - NSMaxRange(range));

        [string addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:20] range:range];

    }

    cell.priceLable.attributedText = string;

 

posted @ 2015-05-19 15:19  在bug中前行  阅读(119)  评论(0)    收藏  举报