NSAttributedString分类-计算富文本高度

来源:互联网 发布:无损音乐软件 编辑:程序博客网 时间:2024/05/21 04:20

- (id)safeObjectAtIndexedSubscript:(NSUInteger)index { if (index >= self.count) { return nil; } elsereturn [selfobjectAtIndex:index]; } }   - (id)safeObjectAtIndex:(NSUInteger)index { if (index >= self.count) { return nil; } elsereturn [selfobjectAtIndex:index]; } }   + (instancetype)safeArrayWithObject:(id)object { if (object == nil) { return [selfarray]; } elsereturn [selfarrayWithObject:object]; } }   - (NSArray *)safeSubarrayWithRange:(NSRange)range { NSUInteger location = range.locationNSUInteger length = range.lengthif (location + length > self.count) { //超过了边界,就获取从loction开始所有的item if ((location + length) > self.count) { length = (self.count - location); return [selfsafeSubarrayWithRange:NSMakeRange(location, length)]; }   return nil; } elsereturn [selfsubarrayWithRange:range]; } }   - (NSUInteger)safeIndexOfObject:(id)anObject { if (anObject == nil) { return NSNotFound; } elsereturn [selfindexOfObject:anObject]; } }     - (NSString *)toJSONStringForArray { NSData *paramsJSONData = [NSJSONSerializationdataWithJSONObject:selfoptions:0error:nil]; return [[NSStringalloc] initWithData:paramsJSONData encoding:NSUTF8StringEncoding]; }