iOS常用方法
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 */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); } }} |
iOS常用方法的更多相关文章
- React Native自定义导航条
Navigator和NavigatorIOS 在开发中,需要实现多个界面的切换,这时候就需要一个导航控制器来进行各种效果的切换.在React Native中RN为我们提供了两个组件:Navigator ...
- ios开发总结:Utils常用方法等收集,添加扩展类,工具类方法,拥有很多方便快捷功能(不断更新中。。。)
BOBUtils 工具大全 本人github开源和收集功能地址:https://github.com/niexiaobo [对ios新手或者工作一年以内开发人员很有用处] 常用方法等收集.添加扩展类. ...
- iOS 25个性能优化/内存优化常用方法
1. 用ARC管理内存 ARC(Automatic ReferenceCounting, 自动引用计数)和iOS5一起发布,它避免了最常见的也就是经常是由于我们忘记释放内存所造成的内存泄露.它自动为你 ...
- IOS 跳转时传参数的常用方法
在iOS开发中常用的参数传递有以下几种方法: 采用代理模式 采用iOS消息机制 通过NSDefault存储(或者文件.数据库存储等) 通过AppDelegate定义全局变量(或者使用UIApplica ...
- iOS UIView常用方法和属性
UIView常用方法 addSubView: // 添加子视图 insertSubview: atIndex // 视图插入到指定索引位置 insertSubview:aboveSubview: // ...
- iOS 锁的常用方法
锁的用法在iOS中有几种方法来解决多线程访问同一个内存地址的互斥同步问题: 方法一,@synchronized(id anObject),(最简单的方法)会自动对参数对象加锁,保证临界区内的代码线程安 ...
- iOS开发——优化篇—— 25个性能优化/内存优化常用方法
1. 用ARC管理内存 ARC(Automatic ReferenceCounting, 自动引用计数)和iOS5一起发布,它避免了最常见的也就是经常是由于我们忘记释放内存所造成的内存泄露.它自动为你 ...
- App 开发中判断 ios 和 andriod 常用方法便于修复在两类机型样式不一样等缺陷
判断安卓, ios
- IOS 中列表的TableView 详解,常用方法整理
一.创建一个列表,不管代码还是nib拖拉,在nib创建的时候,记得加他的二个代理 (UITableViewDelegate UITableViewDataSource) 代码创建的话,需要关联他的代理 ...
随机推荐
- command 'x86_64-linux-gnu-gcc' failed with exit status 1错误及解决方案
Ubuntu16.04安装Scrapy(pip install Scrapy)时提示错误如下: Failed building wheel for cryptography Running setup ...
- AfxBeginThread中使用updatedata出错
原因:MFC对象不支持多线程操作,不能供多个线程进程使用,所以尽量不要在线程里面更新界面. 解决办法: 1.将工程改为release 2.使用控件来SetWindowText 3.在线程里面发送消息 ...
- mysql 范式和反范式
第一范式(1NF)强调的是列的原子性,即列不能够再分成其他几列. 第二范式(2NF) 首先是 2NF,另外包含两部分内容一是表必须有一个主键:二是没有包含在主键中的列必须完全依赖于主键,而不能只依赖于 ...
- [原创]DC-DC输出端加电压会烧毁
在调试智能钥匙连续开锁出现故障的问题排查过程中,为了对比模拟开关TS5A3166对于开锁数据通信的影响,尝试短接模拟开关的输入输出脚,未曾想乌龙了一把,错把DC-DC芯片输入输出短接了(两者都是S ...
- 解决android:background背景图片被拉伸问题
ImageView中XML属性src和background的区别: background会根据ImageView组件给定的长宽进行拉伸,而src就存放的是原图的大小,不会进行拉伸.src是图片内容(前 ...
- linux下关掉teamviewer服务
一.情景介绍 OS: ubuntu14.04 64bit teamviewer版本:10.0.36281 刚才看见已经关掉了teamviewer,但是通过ps看以下进程情况,却还存在该进程,于是: 二 ...
- gulp入门演练
一直想学习下gulp看了蛮多资料,然后总是感觉是是而非,突然开窍了,把自己学会的过程给大家分享下,入门超级简单的 gulp安装 安装gulp 如果参数-g 表示全局安装 $ npm install g ...
- python 02
函数的参数 默认参数: 函数的基本形参, 可以有默认参数, 什么是基本形参呢, 就是普通变量, 如字符串, 数字等. 并且带有默认参数的形参, 要放在后边. 传参时, 不必将所有的参数都传递, 可以只 ...
- DPDK编译步骤
大页内存分配: NUMA系统(现在的linux一般都是) echo 1024 > /sys/devices/system/node/node0/hugepages/hugepages-2048 ...
- grep 使用或条件 ( grep -e )
test@k1rhel5822161:/home/test>cat 31 52 33 24567test@k1rhel5822161:/home/test>grep -e '2|3' 3t ...