1.添加划线(对象方法), NSString的分类:
- (NSMutableAttributedString *)addCancelLine {
NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:self];
[attri addAttributes:@{NSStrikethroughColorAttributeName : [UIColor redColor], NSStrikethroughStyleAttributeName : [NSNumber numberWithInteger:NSUnderlineStyleSingle]} range:NSMakeRange(0, self.length)];
return attri;
}
label.attributedText = [字符串 addCancelLine];
2. 去除字符串尾部的0 例如:$9.900
- (NSString *)cleanDecimalPoint {
NSString *newString = nil;
NSUInteger offset = self.length - 1;
while (offset > 0) {
newString = [self substringWithRange:NSMakeRange(offset, 1)]; //从字符串最后一位开始取一位
if ([newString isEqualToString:@"0"] || [newString isEqualToString:@"."]) {
offset--;
} else {
break;
}
}
return [self substringToIndex:(offset + 1)];
}
3.数组中的内容倒数排列后产生新的装有倒序后的数组
NSArray *reversedArray = [[_contentArray reverseObjectEnumerator] allObjects];
网友评论