1、label的字符替換。用@"2"替換@"1"
NSString *str= [String ByReplacingOccurrencesOfString:@"1"withString:@"2"];
2、label的刪除線
[attributedString addAttribute:NSStrikethroughStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:NSMakeRange(0, 10)];
這樣可以加中劃線,不用自定義lable,直接改字符串屬性就行了
3、將一個數組中的數據用字符串拼接
NSString * imagepic = [strArray componentsJoinedByString:@“,”];//將一個數組中的字符串,以逗號形式隔開
4、一個label設置多種顏色
(1)第一種方法
NSMutableAttributedString*str = [[NSMutableAttributedStringalloc]initWithString:@"合計:¥456.00"];
//設置:在0-3個單位長度內的內容顯示成紅色
[str addAttribute:NSForegroundColorAttributeNamevalue:[UIColor blackColor]range:NSMakeRange(0, 5)];
priceLabel.attributedText= str;
(2)第二種方法
NSMutableAttributedString*noteStr = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"總共公開了%@條文書-符合搜索條件的共有%@條文書",allRemain,searchRemain]];
NSRangeredRange =NSMakeRange([[noteStr string]rangeOfString:allRemain].location, [[noteStr string]rangeOfString:allRemain].length);
[note StraddAttribute:NSForegroundColorAttributeNamevalue:[UIColor redColor]range:redRange];
searchCell.remainLabel.attributedText= noteStr;
5、當label超出多少范圍之后用...替換
if(cell.labelOne.text.length> 35) {
NSString* strText = [cell.labelOne.textsubstringToIndex:35];
cell.labelOne.text= [NSStringstringWithFormat:@"%@...",strText];
}