修改字符串指定範圍的顏色

    UILabel *textLab = [[UILabel alloc] initWithFrame:CGRectMake(spaceW, totalPriceLab.height+totalPriceLab.y, payView.width-2*spaceW, 30*KSCALE_HEIGHT)];
    NSString *timeStr = @"30分鐘";
    NSString *textStr = [NSString stringWithFormat:@"下單後,請在%@內完成付款",timeStr];
    NSMutableAttributedString *attrDescribeStr1 = [[NSMutableAttributedString alloc] initWithString:textStr];
    [attrDescribeStr1 addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:[textStr rangeOfString:timeStr]];
    textLab.attributedText = attrDescribeStr1;
    [payView addSubview:textLab];

相關文章
相關標籤/搜索