字符间距,行间距

//字符间隙

    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:cateString];

    long number = 3.0f;

    CFNumberRef num = CFNumberCreate(kCFAllocatorDefault,kCFNumberSInt8Type,&number);

    [attributedString addAttribute:(id)kCTKernAttributeName value:(__bridge id)num range:NSMakeRange(0,[attributedString length])];

    CFRelease(num);

    [self.kolCateLabel setAttributedText:attributedString];

\\行间距

NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]initWithString:goodsDesStr];;

    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init];

    [paragraphStyle setLineSpacing:7];

    [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [attributedString length])];

    [_goodsDesLabel setAttributedText:attributedString];

\\多字体颜色

   //价格

    NSString * priceStrDiscount = [NDMoneyChange changeformatterWithFen:goodsInfo.goodsDiscountPrice];

    NSString * priceStrOrigin =  [NDMoneyChange changeformatterWithFen:goodsInfo.goodsOriginalPrice];

    NSString * priceString;

    NSRange  discountPriceRange;

    NSRange  orginPriceRange;

    if ([goodsInfo.goodsOriginalPrice isEqual:goodsInfo.goodsDiscountPrice]) {

        

        priceString = priceStrDiscount;

    }else

    {

        priceString = [NSString stringWithFormat:@"%@  %@",priceStrDiscount,priceStrOrigin];

        orginPriceRange = [priceString rangeOfString:priceStrOrigin];

    }

    NSMutableAttributedString * priceStr = [[NSMutableAttributedString alloc]initWithString:priceString];

    

    discountPriceRange = [priceString rangeOfString:priceStrDiscount];

    [priceStr addAttribute:NSForegroundColorAttributeName value:kMainRedColor range:discountPriceRange];

    [priceStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:21.0f] range:discountPriceRange];

    

    if (![goodsInfo.goodsOriginalPrice isEqual:goodsInfo.goodsDiscountPrice]) {

        

        [priceStr addAttribute:NSForegroundColorAttributeName value:kSubColor range:orginPriceRange];

        [priceStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12.0f] range:orginPriceRange];

        

        [priceStr addAttribute:NSStrikethroughStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:orginPriceRange];

    }

    [_priceLabel setAttributedText:priceStr];


你可能感兴趣的:(字符间距,行间距)