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。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值