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];
}