美文网首页
iOS一些知识点

iOS一些知识点

作者: 大大东 | 来源:发表于2017-06-27 17:25 被阅读20次
    1. 给一个view截图
        UIGraphicsBeginImageContextWithOptions(view.bounds.size, YES, 0.0);
        [view.layer renderInContext:UIGraphicsGetCurrentContext()];
        UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
    
    1. 颜色转图片
     + (UIImage *)dl_imageWithColor:(UIColor *)color {
        CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
        UIGraphicsBeginImageContext(rect.size);
        CGContextRef context = UIGraphicsGetCurrentContext();
        
        CGContextSetFillColorWithColor(context, [color CGColor]);
        CGContextFillRect(context, rect);
        
        UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        return image;
    }
    
    1. 监听用户修改了本地时间
    NSSystemTimeZoneDidChangeNotification监听修改时间界面的两个按钮状态变化
    UIApplicationSignificantTimeChangeNotification 监听用户改变时间 (只要点击自动设置按钮就会调用) 
    NSSystemClockDidChangeNotification 监听用户修改时间(时间不同才会调用)
    
    1. collectionView的内容小于其宽高的时候是不能滚动的,设置可以滚动:
    collectionView.alwaysBounceHorizontal = YES;
    collectionView.alwaysBounceVertical = YES;
    
    1. 修改NSLog
    #ifdef DEBUG
    #define NSLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
    #else
    #define NSLog(...)
    #endif
    
    1. 长按复制
     - (void)viewDidLoad
    {
        [self.view addGestureRecognizer:[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(pasteBoard:)]];
    }
     - (void)pasteBoard:(UILongPressGestureRecognizer *)longPress {
        if (longPress.state == UIGestureRecognizerStateBegan) {
            UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
            pasteboard.string = @"需要复制的文本";
        }
    }
    
    1. 获取userAgent
    +(NSString*)userAgent
    {
        static NSString *userAgent = @"";
        static dispatch_once_t onceToken;
        dispatch_once(&onceToken, ^{
            userAgent = [[UIWebView new] stringByEvaluatingJavaScriptFromString:@"navigator.userAgent"];
        });
        return userAgent;
    }
    
    1. afnetworking 过滤NSNULL
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
        
        AFJSONResponseSerializer *serializer = [AFJSONResponseSerializer serializer];
        serializer.removesKeysWithNullValues = YES;
        manager.responseSerializer = serializer;
    
    1. 修改UITextfile ,UISearchBar的placehold的fontColor
    UITextField *searchField = [searchBar valueForKey:@"_searchField"]; 
    [searchField setValue:[UIColor blueColor] forKeyPath:@"_placeholderLabel.textColor"];
    
    1. 禁止同时点点击多个控件,避免同时响应多个事件
    // UIView有个属性叫做exclusiveTouch,设置为YES后,其响应事件会和其他view互斥(有其他view事件响应的时候点击它不起作用) 
    view.exclusiveTouch = YES; // 一个一个设置太麻烦了,可以全局设置 
    [[UIView appearance] setExclusiveTouch:YES]; // 或者只设置button 
    [[UIButton appearance] setExclusiveTouch:YES];
    

    相关文章

      网友评论

          本文标题:iOS一些知识点

          本文链接:https://www.haomeiwen.com/subject/unnscxtx.html