天天看點

ios :一個Label 顯示兩種顔色的寫法

NSMutableAttributedString *commentAttrString = [[NSMutableAttributedString alloc] initWithString:@" 條評論" attributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:],NSForegroundColorAttributeName:[[TinyVideo5Theme yy5Theme] getColorWithColorString:COLOR_1]}];

    NSAttributedString *commentCountAttrString = [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@",@(commentCount)] attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:],NSForegroundColorAttributeName:[[TinyVideo5Theme yy5Theme] getColorWithColorString:COLOR_4]}];

    NSMutableAttributedString *commentString = [[NSMutableAttributedString alloc] init];
    [commentString appendAttributedString: commentCountAttrString];
    [commentString appendAttributedString: commentAttrString];

    self.commentHeadLabel.attributedText = commentString;
           

效果圖:

ios :一個Label 顯示兩種顔色的寫法