2019独角兽企业重金招聘Python工程师标准>>>

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]; //创建27个分组数组 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]; //创建27个分组数组 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.对图片进行滤镜处理 // 怀旧 --> CIPhotoEffectInstant 单色 --> CIPhotoEffectMono // 黑白 --> CIPhotoEffectNoir 褪色 --> CIPhotoEffectFade // 色调 --> CIPhotoEffectTonal 冲印 --> CIPhotoEffectProcess // 岁月 --> CIPhotoEffectTransfer 铬黄 --> CIPhotoEffectChrome // CILinearToSRGBToneCurve, CISRGBToneCurveToLinear, CIGaussianBlur, CIBoxBlur, CIDiscBlur, CISepiaTone, CIDepthOfField

  • (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.对图片进行模糊处理 // CIGaussianBlur ---> 高斯模糊 // CIBoxBlur ---> 均值模糊(Available in iOS 9.0 and later) // CIDiscBlur ---> 环形卷积模糊(Available in iOS 9.0 and later) // CIMedianFilter ---> 中值模糊, 用于消除图像噪点, 无需设置radius(Available in iOS 9.0 and later) // CIMotionBlur ---> 运动模糊, 用于模拟相机移动拍摄时的扫尾效果(Available in iOS 9.0 and later)

  • (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.跳转到系统的相关界面: /*

  • 需要添加一个字段
  • 蓝色的项目工程文件 -> Info -> URL Types -> 添加一个 -> 设置URL Sch**** 为 prefs的url

NSURL *url = [NSURL URLWithString:@"prefs:root=WIFI"]; [[UIApplication sharedApplication] openURL:url];

跳转到其他的界面的字段(不全,详细看链接) About — prefs:root=General&path=About

Accessibility — prefs:root=General&path=ACCESSIBILITY

AirplaneModeOn— prefs:root=AIRPLANE_MODE

Auto-Lock — prefs:root=General&path=AUTOLOCK

Brightness — prefs:root=Brightness

Bluetooth — prefs:root=General&path=Bluetooth

Date& Time — prefs:root=General&path=DATE_AND_TIME

FaceTime — prefs:root=FACETIME

General— prefs:root=General

原文链接:http://www.jianshu.com/p/19602f48309b

*/

8.创建一张实时模糊效果 View (毛玻璃效果) //Avilable in iOS 8.0 and later

  • (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);}
    

    } }

转载于:https://my.oschina.net/u/2483781/blog/707061

Objective-c 实用代码相关推荐

  1. java 字符处理_Java字符串处理实用代码

    您的位置:首页 - 教程 - Java - 正文 Java字符串处理实用代码 package myjava; public class Mystring { public static void ma ...

  2. Android实用代码七段(五)

    1.展开.收起状态栏 public static final void collapseStatusBar(Context ctx) {         Object sbservice = ctx. ...

  3. Android实用代码(不定期更新)

    Android实用代码七段(一) 一抹火焰 整理(不定期更新) 前言 这里积累了一些不常见确又很实用的代码,每收集7条更新一次,希望能对大家有用. 声明: 欢迎转载,但请保留文章原始出处:)  博客园 ...

  4. java定时器检测状态_实用代码| shell脚本实现定时检查应用状态

    关注"java从心",置顶公众号 每天进步一点点,距离大腿又近一步! 阅读本文大概需要5分钟 有时候,我们挂在服务器上的应用会因为一些特殊情况挂掉,致使项目经理又对我们说:又挂了! ...

  5. 这也太狠了吧!500套Java实用代码,不论工作学习都能用到!

    资源来自网络,如侵权请告知博主删除. 作为一个程序员,随着工作时间的增加,慢慢就会有自己的一个代码库,不管是编程的工具,或者是一个拿来用改造的项目,或者说是学习用的,总之,这样的一个库必不可少,给大家 ...

  6. android实用代码

    Android实用代码七段(一) 前言 这里积累了一些不常见确又很实用的代码,每收集7条更新一次,希望能对大家有用. 声明 欢迎转载,但请保留文章原始出处:)  博客园:http://www.cnbl ...

  7. 增强中获取屏幕值的一句很实用代码…

    增强中获取屏幕值的一句很实用代码,直接获取屏幕字段值, 一般是在增强中用 比如MIGO收货时,希望获取收货对应的A01这个值 增强:BADI:  MB_DOCUMENT_BADI  MB_DOCUME ...

  8. ul、li列表简单实用代码实例

    利用ul和li可以实现列表效果,下面就是一个简单的演示. 代码如下: 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 ...

  9. 做网页很实用代码集合和CSS制作网页小技巧整理

    做网页很实用代码集合 控制横向和纵向滚动条的显隐?<body style="overflow-y:hidden"> 去掉x轴 <body style=" ...

  10. python数据挖掘学习笔记】十.Pandas、Matplotlib、PCA绘图实用代码补充

    #2018-03-23 18:56:38 March Friday the 12 week, the 082 day SZ SSMR https://blog.csdn.net/eastmount/a ...

最新文章

  1. 二叉树结点地址小错误
  2. Android4.0 Design之UI设计易犯的错误1
  3. 波士顿动力CEO:不排斥军方订单,就想你粗暴地对待机器狗
  4. ubuntu搭建jdk1.8运行环境(下载jdk方式)
  5. 网络设备中的集线器(Hub)是什么?—Vecloud微云
  6. 【libsvm 错误使用mex】
  7. lisp 绘制立体感的五角星_[原创]圆内加五角星lsp代码,详细有注解
  8. 福布斯发布美国富豪榜:贝索斯居首 盖茨跌出前二
  9. js 接收 json格式的字符串
  10. Codeforces.741D.Arpa’s letter-marked tree and Mehrdad’s Dokhtar-kosh paths(dsu on tree 思路)
  11. SenchaEclipsePlugin-1.1.0的使用
  12. STM32CubeIDE 下载及安装教程
  13. 优班图linux 命令,Linux 常用命令
  14. 扬帆凌远:从美妆品牌案例看品牌思维
  15. Pytorch 深度学习实战教程(五):今天,你垃圾分类了吗?
  16. 【uniapp | 微信小程序】注册和开发环境搭建
  17. JavaScript:100以内质数1000以内的质数显示和统计
  18. html怎么打出一个圆点,如何打出两个字中间的圆点
  19. js中单引号和双引号的使用区别
  20. 论文翻译-On Recognizing Texts of Arbitrary Shapes with 2D Self-Attention

热门文章

  1. WSL系列操作:安装,卸载
  2. CSDN-markdown编辑器
  3. java产生死锁的主要原因_详解java中产生死锁的原因及如何避免
  4. 计数时钟和滚动汉字显示c语言程序,MSP430F449单片机RTC时钟C语言程序(带闹钟)...
  5. Spring-Boot-Bean的使用,@Repository,@Service,@Controller,@Component
  6. centos7 pam mysql.so,Centos7下搭建FTP服务器(博主亲测不坑)
  7. linux 自定义外壳,管道在自定义的linux外壳
  8. php点击按钮加载控制器,php – Codeigniter 3自动加载控制器
  9. Python的零基础超详细讲解(第三天)-Python的基础语法
  10. 数据库字典php样色,使用PHP一键生成MySQL数据库字典