iOS之常用知识点汇总

开发中遇到了以前用过的知道的知识点,就懒得再去写了,要么从之前的项目中找,要么去谷歌百度再去筛选,这样很影响开发效率。所以,好记性不如烂笔头,把常用的知识点汇总了一下,下次需要时,直接打开项目笔记,全局搜索,几秒搞定。gitHub下载地址:https://github.com/leeSmile/iOSknowledgeGather

.h文件知识点目录

/*
 1.NSString过滤特殊字符
 2.TransForm属性
 3.计算方法耗时时间间隔
 4.Alert提示宏定义
 5.让iOS应用直接退出
 6.快速求总和 最大值 最小值 和 平均值
 7.修改Label中不同文字颜色
 8.Label行间距
 9.UIImageView填充模式
 10.iOS 开发中一些相关的路径
 11.关于隐藏navigationbar
 12.自动处理键盘事件,实现输入框防遮挡的插件
 13.设置字体和行间距
 14.点击button倒计时
 15.修改textFieldplaceholder字体颜色和大小
 16.图片拉伸
 17.去掉导航栏下边的黑线
 18.修改pagecontrol颜色
 19.去掉UITableView的section的粘性,使其不会悬停
 20.UIImage与字符串互转
 21.判断NSString中是否包含中文
 22.NSDate与NSString的相互转化
 23.控件的局部圆角
 24.navigationBar的透明问题
 25.全局设置navigationBar标题的样式和barItem的标题样式
 26.侧滑手势返回
 27.给webView添加头视图
 28.模态跳转的动画设置
 29.图片处理只拿到图片的一部分
 30.给UIView设置图片
 31.给TableView或者CollectionView的cell添加简单动画
 32.线程中更新 UILabel的text
 33.获得当前硬盘空间
 34.ActivityViewController 使用AirDrop分享
 35.保存全屏为image
 36.获取通讯录联系人的电话号码
 37.用WebView加载页面,提前获取页面的高度
 */

.m文件部分知识点实现

#pragma 37.用WebView加载页面,提前获取页面的高度
    可以获得内容高度,但是网络不好时,不准确
  1.webView.scrollView.contentSize.height; 
    获取的高度较为准确
  2.[[webView stringByEvaluatingJavaScriptFromString:@"document.body.offsetHeight;"] intValue]

#pragma 36.获取通讯录联系人的电话号码
                                                        
#import <AddressBook/AddressBook.h>
#import <AddressBookUI/AddressBookUI.h>
ABPeoplePickerNavigationControllerDelegate
                                                        
    - (void)addAddress
    {
    RYLog(@"选择联系人");
    ABPeoplePickerNavigationController * vc = [[ABPeoplePickerNavigationController alloc] init];
    vc.peoplePickerDelegate = self;
    [self presentViewController:vc animated:YES completion:nil];

    }

    #pragma mark -- ABPeoplePickerNavigationControllerDelegate
    - (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController*)peoplePicker didSelectPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier {

    ABMultiValueRef valuesRef = ABRecordCopyValue(person, kABPersonPhoneProperty);
    CFIndex index = ABMultiValueGetIndexForIdentifier(valuesRef,identifier);
    //电话号码
    CFStringRef telValue = ABMultiValueCopyValueAtIndex(valuesRef,index);

    [self dismissViewControllerAnimated:YES completion:^{
    self.addressV.telnum.text = (__bridge NSString *)telValue;

    }];
    }

#pragma 35.保存全屏为image
                                                        
    CGSize imageSize = [[UIScreen mainScreen] bounds].size;
    UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0);
    CGContextRef context = UIGraphicsGetCurrentContext();

    for (UIWindow * window in [[UIApplication sharedApplication] windows]) {
    if (![window respondsToSelector:@selector(screen)] || [window screen] == [UIScreen mainScreen]) {
    CGContextSaveGState(context);
    CGContextTranslateCTM(context, [window center].x, [window center].y);
    CGContextConcatCTM(context, [window transform]);
    CGContextTranslateCTM(context, -[window bounds].size.width*[[window layer] anchorPoint].x, -[window bounds].size.height*[[window layer] anchorPoint].y);
    [[window layer] renderInContext:context];

    CGContextRestoreGState(context);
    }
    }
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();


#pragma 34.ActivityViewController 使用AirDrop分享
    使用AirDrop 进行分享:
        NSArray *array = @[@"test1", @"test2"];

        UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:array applicationActivities:nil];
    
        [self presentViewController:activityVC animated:YES
                         completion:^{
                             NSLog(@"Air");
                         }];


#pragma 33.获得当前硬盘空间
    NSFileManager *fm = [NSFileManager defaultManager];
    NSDictionary *fattributes = [fm attributesOfFileSystemForPath:NSHomeDirectory() error:nil];
    
    NSLog(@"容量%lldG",[[fattributes objectForKey:NSFileSystemSize] longLongValue]/1000000000);
    NSLog(@"可用%lldG",[[fattributes objectForKey:NSFileSystemFreeSize] longLongValue]/1000000000);

这是部分知识点的实现,完整的请在github上下载,欢迎star。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 172,861评论 25 708
  • 诗之贵 贵在 寥寥数字束在方寸间 可表达之情却在大地 万物中升腾 爱 是这样 情 也是这样
    快门pogo手大村阅读 163评论 0 1
  • 手 携 稚 子 飞 天 风 牵 老 牛 云 端 相 会 银 河 边 织 女 鹊 桥 卧 栏 卧 兰 卧 兰 泪 洒...
    水墨悠然阅读 372评论 13 21
  • 今个早,我还特意去看了看日历,离开简书估摸着应该有7个月了。 没有写文字的日子怎么就过得贼快呢?一溜烟儿就没了,感...
    六便士芮妮阅读 295评论 2 2
  • 一、关于生活方面: (1)完成晨路10公里,并坚持听《精英日课》 2、关于读书与自我迭代方面: (1)保证收听专栏...
    清风_bd61阅读 320评论 0 0