知识整理

1、调整TableViewCell的分割线到左边的距离

-(void)viewDidLayoutSubviews {
    if ([self.tableview respondsToSelector:@selector(setSeparatorInset:)]) {
        [self.tableview setSeparatorInset:UIEdgeInsetsZero];
    }
    if ([self.tableview respondsToSelector:@selector(setLayoutMargins:)])  {
        [self.tableview setLayoutMargins:UIEdgeInsetsZero];
    }
}

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPat{
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]){
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }
}

2、TableView滚动时收起键盘

tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;

另外一个枚举为UIScrollViewKeyboardDismissModeInteractive,表示在键盘内部滑动,键盘逐渐下去。

3、滑动时隐藏导航条

navigationController.hidesBarsOnSwipe = Yes;

4、禁止程序自动锁屏

[[UIApplication sharedApplication] setIdleTimerDisabled:YES];

5、修改UITextField的placeholder的颜色和字体

[textField setValue:[UIColor redColor] forKeyPath:@"_placeholderLabel.textColor"];  
[textField setValue:[UIFont boldSystemFontOfSize:16] forKeyPath:@"_placeholderLabel.font"];

6、隐藏UITabBar

UIViewController *vc = [UIViewController new];
vc.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:vc animated:YES];

7、取消系统的返回手势

self.navigationController.interactivePopGestureRecognizer.enabled = NO;

8、AFnetWorking报”Request failed: unacceptable content-type: text/html”错误

AFURLResponseSerialization.m
self.acceptableContentTypes = [NSSetsetWithObjects:@"application/json", @"text/html",@"text/json",@"text/javascript", nil];

9、隐藏navigation跳转后的返回按钮

//隐藏头部左边的返回
self.navigationItem.hidesBackButton=YES;

10、两种方法删除NSUserDefaults所有记录

//方法一
NSString *appDomain = [[NSBundle mainBundle] bundleIdentifier];
[[NSUserDefaults standardUserDefaults] removePersistentDomainForName:appDomain];

//方法二
- (void)resetDefaults {
    NSUserDefaults * defs = [NSUserDefaults standardUserDefaults];
    NSDictionary * dict = [defs dictionaryRepresentation];
    for (id key in dict) {
        [defs removeObjectForKey:key];
    }
    [defs synchronize];
}

11、NSLog的格式输出

• %@     对象
• %d, %i    整数
• %u      无符整形
• %f       浮点/双字
• %x, %X   二进制整数
• %o      八进制整数
• %zu     size_t
• %p      指针
• %e      浮点/双字 (科学计算)
• %g      浮点/双字
• %s       C 字符串
• %.*s      Pascal字符串
• %c       字符
• %C       unichar
• %lld      64位长整数(long long)
• %llu      无符64位长整数
• %Lf       64位双字

12、绘制1像素的线

#define SINGLE_LINE_WIDTH           (1 / [UIScreen mainScreen].s 大专栏  知识整理cale)
#define SINGLE_LINE_ADJUST_OFFSET   ((1 / [UIScreen mainScreen].scale) / 2)

UIView *view = [[UIView alloc] initWithFrame:CGrect(x - SINGLE_LINE_ADJUST_OFFSET, 0, SINGLE_LINE_WIDTH, 100)];

13、去除编译器警告

//-Wdeprecated-declarations 编译器警告的类型

#pragma clang diagnostic push  

#pragma clang diagnostic ignored "-Wdeprecated-declarations"      

#pragma clang diagnostic pop  

14、判断视图是否发生形变

if (CGAffineTransformIsIdentity(self.view.transform))
{//还原形变
    self.view.transform = CGAffineTransformIdentity;
}

15、Pod更新

pod install --verbose --no-repo-update
pod update --verbose --no-repo-update

16、获取Collection的ContentSize

self.collectionViewH = self.flowLayout.collectionViewContentSize.height;

17、跳转进入app的设置界面

NSURL * url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
if([[UIApplication sharedApplication] canOpenURL:url]) {
          NSURL*url =[NSURL           
           URLWithString:UIApplicationOpenSettingsURLString];
           [[UIApplication sharedApplication] openURL:url];
}

18、App进行评分

NSString *str = [NSString stringWithFormat:@"itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=xxxxxx" ];

if( ([[[UIDevice currentDevice] systemVersion] doubleValue]>=7.0)){

           str = [NSString stringWithFormat:@"itms-apps://itunes.apple.com/app/idxxxxxxx"];

}

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];

19、多个异步任务进行处理

// 1.创建dispatch_group_t
dispatch_group_t group = dispatch_group_create();

for (int i=0; i<10; i++) {

     // 2、将当前的下载操作添加到组中
      dispatch_group_enter(group);

        {
              // 数据请求成功离开当前组
             dispatch_group_leave(group);
        }

}
// 3.当所有图片都下载完毕再通过闭包通知调用者

dispatch_group_notify(group, dispatch_get_main_queue(), ^{

         // 能够来到这个地方, 一定是所有任务都已经完成
});

20、label设置删除线

UILabel *originPriceLabel = [UILabel new];

NSString *originPriceString = [NSString stringWithFormat:@"¥ %@0", @"100"];

NSMutableAttributedString *originPriceAttrsStr = [[NSMutableAttributedString alloc] initWithString:originPriceString];

[originPriceAttrsStr addAttribute:NSStrikethroughStyleAttributeName value:@(1)

range:NSMakeRange(0, originPriceString.length)];

originPriceLabel.attributedText = originPriceAttrsStr;

21、设置textView或者label的行间距方法

UILabel *label = [UILabel new];
label.numberOfLines = 0;
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
paragraphStyle.lineSpacing = 4;
NSDictionary *attributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:14], NSParagraphStyleAttributeName:paragraphStyle};
label.attributedText = [[NSAttributedString alloc]initWithString:label.text attributes:attributes];

22、UIImageView设置圆角时产生UI不流畅的解决

//        只需要加上这段代码就可以去除锯齿
imageView.layer.shouldRasterize = YES;
当shouldRasterize设成true时,layer被渲染成一个bitmap,并缓存起来,等下次使用时不会再重新去渲染了。实现圆角本身就是在做颜色混合(blending),如果每次页面出来时都blending,消耗太大,这时shouldRasterize = yes,下次就只是简单的从渲染引擎的cache里读取那张bitmap,节约系统资源。

额外收获:如果在滚动tableView时,每次都执行圆角设置,肯定会阻塞UI,设置这个将会使滑动更加流畅。
原文链接:http://blog.csdn.net/zhuangyou123/article/details/8737367
上一篇:2016 Technology Salary Report (GTA) from Lannick


下一篇:My Top Network Security Tools