1.磁盘总空间大小
+ (CGFloat)diskOfAllSizeMBytes
{
CGFloat size = 0.0;
NSError *error;
NSDictionary *dic = [[NSFileManager defaultManager] attributesOfFileSystemForPath:NSHomeDirectory() error:&error];
if
(error) {
#ifdef DEBUG
NSLog(@
"error: %@"
, error.localizedDescription);
#endif
}
else
{
NSNumber *number = [dic objectForKey:NSFileSystemSize];
size = [number floatValue]/1024/1024;
}
return
size;
}
2.磁盘可用空间大小
+ (CGFloat)diskOfFreeSizeMBytes
{
CGFloat size = 0.0;
NSError *error;
NSDictionary *dic = [[NSFileManager defaultManager] attributesOfFileSystemForPath:NSHomeDirectory() error:&error];
if
(error) {
#ifdef DEBUG
NSLog(@
"error: %@"
, error.localizedDescription);
#endif
}
else
{
NSNumber *number = [dic objectForKey:NSFileSystemFreeSize];
size = [number floatValue]/1024/1024;
}
return
size;
}
3.将字符串数组按照元素首字母顺序进行排序分组
+ (NSDictionary *)dictionaryOrderByCharacterWithOriginalArray:(NSArray *)array
{
if
(array.count == 0) {
return
nil;
}
for
(id obj in array) {
if
(![obj isKindOfClass:[NSString
class
]]) {
return
nil;
}
}
UILocalizedIndexedCollation *indexedCollation = [UILocalizedIndexedCollation currentCollation];
NSMutableArray *objects = [NSMutableArray arrayWithCapacity:indexedCollation.sectionTitles.count];
for
(
int
i = 0; i < indexedCollation.sectionTitles.count; i++) {
NSMutableArray *obj = [NSMutableArray array];
[objects addObject:obj];
}
NSMutableArray *keys = [NSMutableArray arrayWithCapacity:objects.count];
NSInteger lastIndex = -1;
for
(
int
i = 0; i < array.count; i++) {
NSInteger index = [indexedCollation sectionForObject:array[i] collationStringSelector:@selector(uppercaseString)];
[[objects objectAtIndex:index] addObject:array[i]];
lastIndex = index;
}
for
(
int
i = 0; i < objects.count; i++) {
NSMutableArray *obj = objects[i];
if
(obj.count == 0) {
[objects removeObject:obj];
}
}
for
(NSMutableArray *obj in objects) {
NSString *str = obj[0];
NSString *key = [self firstCharacterWithString:str];
[keys addObject:key];
}
NSMutableDictionary *dic = [NSMutableDictionary dictionary];
[dic setObject:objects forKey:keys];
return
dic;
}
4.将字符串数组按照元素首字母顺序进行排序分组
+ (NSDictionary *)dictionaryOrderByCharacterWithOriginalArray:(NSArray *)array
{
if
(array.count == 0) {
return
nil;
}
for
(id obj in array) {
if
(![obj isKindOfClass:[NSString
class
]]) {
return
nil;
}
}
UILocalizedIndexedCollation *indexedCollation = [UILocalizedIndexedCollation currentCollation];
NSMutableArray *objects = [NSMutableArray arrayWithCapacity:indexedCollation.sectionTitles.count];
for
(
int
i = 0; i < indexedCollation.sectionTitles.count; i++) {
NSMutableArray *obj = [NSMutableArray array];
[objects addObject:obj];
}
NSMutableArray *keys = [NSMutableArray arrayWithCapacity:objects.count];
NSInteger lastIndex = -1;
for
(
int
i = 0; i < array.count; i++) {
NSInteger index = [indexedCollation sectionForObject:array[i] collationStringSelector:@selector(uppercaseString)];
[[objects objectAtIndex:index] addObject:array[i]];
lastIndex = index;
}
for
(
int
i = 0; i < objects.count; i++) {
NSMutableArray *obj = objects[i];
if
(obj.count == 0) {
[objects removeObject:obj];
}
}
for
(NSMutableArray *obj in objects) {
NSString *str = obj[0];
NSString *key = [self firstCharacterWithString:str];
[keys addObject:key];
}
NSMutableDictionary *dic = [NSMutableDictionary dictionary];
[dic setObject:objects forKey:keys];
return
dic;
}
5.对图片进行滤镜处理
+ (UIImage *)filterWithOriginalImage:(UIImage *)image filterName:(NSString *)name
{
CIContext *context = [CIContext contextWithOptions:nil];
CIImage *inputImage = [[CIImage alloc] initWithImage:image];
CIFilter *filter = [CIFilter filterWithName:name];
[filter setValue:inputImage forKey:kCIInputImageKey];
CIImage *result = [filter valueForKey:kCIOutputImageKey];
CGImageRef cgImage = [context createCGImage:result fromRect:[result extent]];
UIImage *resultImage = [UIImage imageWithCGImage:cgImage];
CGImageRelease(cgImage);
return
resultImage;
}
6.对图片进行模糊处理
+ (UIImage *)blurWithOriginalImage:(UIImage *)image
blurName:(NSString *)name
radius:(NSInteger)radius
{
CIContext *context = [CIContext contextWithOptions:nil];
CIImage *inputImage = [[CIImage alloc] initWithImage:image];
CIFilter *filter;
if
(name.length != 0) {
filter = [CIFilter filterWithName:name];
[filter setValue:inputImage forKey:kCIInputImageKey];
if
(![name isEqualToString:@
"CIMedianFilter"
]) {
[filter setValue:@(radius) forKey:@
"inputRadius"
];
}
CIImage *result = [filter valueForKey:kCIOutputImageKey];
CGImageRef cgImage = [context createCGImage:result fromRect:[result extent]];
UIImage *resultImage = [UIImage imageWithCGImage:cgImage];
CGImageRelease(cgImage);
return
resultImage;
}
else
{
return
nil;
}
}
7.跳转到系统的相关界面:
8.创建一张实时模糊效果 View (毛玻璃效果)
+ (UIVisualEffectView *)effectViewWithFrame:(CGRect)frame
{
UIBlurEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
UIVisualEffectView *effectView = [[UIVisualEffectView alloc] initWithEffect:effect];
effectView.frame = frame;
return
effectView;
}
9.设置Label的行间距
+ (
void
)setLineSpaceWithString:(UILabel *)label
{
NSMutableAttributedString *attributedString =
[[NSMutableAttributedString alloc] initWithString:label.text];
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
[paragraphStyle setLineSpacing:3];
[attributedString addAttribute:NSParagraphStyleAttributeName
value:paragraphStyle
range:NSMakeRange(0, [label.text length])];
label.attributedText = attributedString;
}
10.让Plain风格的TableView的区头可以”不悬停”(可以直接百度搜到):
- (
void
)scrollViewDidScroll:(UIScrollView *)scrollView
{
if
(scrollView == self.myTab) {
CGFloat sectionHeaderHeight = 40;
if
(scrollView.contentOffset.y=0) {
scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);
}
else
if
(scrollView.contentOffset.y>=sectionHeaderHeight) {
scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);
}
}
}