富文本二

//富文本
UILabel *amountlabel = [[UILabel alloc] init];
amountlabel.font = [UIFont systemFontOfSize:14];
amountlabel.textColor=[UIColor colorWithHex:0xfc5c98];
NSString conststr = @"3360";
NSString
dadanumber=@"搭币数量:";
NSString *praisestr = [NSString stringWithFormat:@"%@ %@ 搭币",dadanumber,conststr];
NSMutableAttributedString *costattrDescribeStr = [[NSMutableAttributedString alloc] initWithString:praisestr];

    [costattrDescribeStr addAttribute:NSForegroundColorAttributeName
     
                                value:[UIColor colorWithHex:0x737373]
     
                                range:[praisestr  rangeOfString:dadanumber]];
    
    [costattrDescribeStr addAttribute:NSFontAttributeName
     
                                value:[UIFont systemFontOfSize:18.0]
     
                                range:[praisestr  rangeOfString:conststr]];

// NSDictionary *dic = @{NSKernAttributeName:@2.0f};
// [costattrDescribeStr addAttributes:dic range:[praisestr rangeOfString:conststr]];//设置字体间距 这边采用全角空格因此不设置

    amountlabel.attributedText = costattrDescribeStr;
    amountlabel.textAlignment=NSTextAlignmentLeft;
    [optionview addSubview:amountlabel];
    [amountlabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(@-15);
        make.right.equalTo(@-12);
    }];
    _amountlabel=amountlabel;

你可能感兴趣的:(富文本二)