知识点

作者: yayun_he | 来源:发表于2016-12-07 11:20 被阅读0次

    平时记录的一些零碎的东西~ ~ 欢迎一起分享

    MJExtesion 当model有数组时,数组内你又可以在复制一次model:例如:

    .h
    #import <Foundation/Foundation.h>
    @interface LGOrderDetailObj : NSObject
    //此数组中仍可以组成一个model
    @property (nonatomic, strong) NSMutableArray *extend_order_goods;
    @end
    
    @interface SpecialGoodsModel : NSObject
    @property (nonatomic, copy) NSString *goods_name;
    @property (nonatomic, copy) NSString *goods_image;
    // 商品规格
    @property (nonatomic, strong) NSArray *goods_specification;
    @end
    
    .m
    #import "LGOrderDetailObj.h"
    @implementation LGOrderDetailObj
    // 再次转换model
    +(NSDictionary *)objectClassInArray {
        return @{@"extend_order_goods":@"SpecialGoodsModel"};
    }
    @end
    
    @implementation SpecialGoodsModel
    @end
    

    for in与for

    for in快速遍历的时候,如果是可变数组字典之类的,不能对其进行增删改操作,否则会抛出异常
    

    xcode8多个模拟器问题

    首先退出Xcode并且关闭模拟器:
    然后在终端(Terminal)输入如下2行命令:
    **sudo killall -9 com.apple.CoreSimulator.CoreSimulatorService**
    **rm -rf ~/Library/Developer/CoreSimulator/Devices**
    

    JSONView

    1、早GitHub中下载
    2、在googol中打开这个链接  chrome://extensions/
    3、选中开发者模式
    4、加载正在开发的扩展程序   选中解压后的文件(WebContent)  添加即可
    

    二维码生成,高清二维码, 收藏中有详细讲解

    /**
     *  生成二维码
     */
    - (UIImage *)imageFromQrWith:(NSString *)string withSize:(CGFloat)size{
        CIFilter *filter = [CIFilter filterWithName:@"CIQRCodeGenerator"];
        [filter setDefaults];
        NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
        [filter setValue:data forKey:@"inputMessage"];
        CIImage *outputImage = [filter outputImage];  
        return [self createNonInterpolatedUIImageFormCIImage:outputImage withSize:size];
    }
    // 二维码高清处理,CIImage –> CGImageRef –> UIImage
    - (UIImage *)createNonInterpolatedUIImageFormCIImage:(CIImage *)image withSize:(CGFloat) size {
        CGRect extent = CGRectIntegral(image.extent);
        //设置比例
        CGFloat scale = MIN(size/CGRectGetWidth(extent), size/CGRectGetHeight(extent));
        // 创建bitmap(位图);
        size_t width = CGRectGetWidth(extent) * scale;
        size_t height = CGRectGetHeight(extent) * scale;
        CGColorSpaceRef cs = CGColorSpaceCreateDeviceGray();
        CGContextRef bitmapRef = CGBitmapContextCreate(nil, width, height, 8, 0, cs, (CGBitmapInfo)kCGImageAlphaNone);
        CIContext *context = [CIContext contextWithOptions:nil];
        CGImageRef bitmapImage = [context createCGImage:image fromRect:extent];
        CGContextSetInterpolationQuality(bitmapRef, kCGInterpolationNone);
        CGContextScaleCTM(bitmapRef, scale, scale);
        CGContextDrawImage(bitmapRef, extent, bitmapImage);
        // 保存bitmap到图片
        CGImageRef scaledImage = CGBitmapContextCreateImage(bitmapRef);
        CGContextRelease(bitmapRef);
        CGImageRelease(bitmapImage);
        return [UIImage imageWithCGImage:scaledImage];
    }
    

    中文参数转码

    - (NSString *)encodeToPercentEscapeString: (NSString *) input
    {
        // Encode all the reserved characters, per RFC 3986
        NSString *outputStr = (NSString *)
        CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,
                                                                  (CFStringRef)input,
                                                                  NULL,
                                                                  (CFStringRef)@"!*'();:@&=+$,/?%#[]",
                                                                  kCFStringEncodingUTF8));
        return outputStr;
    }
    

    将汉字转化为拼音字符串获取大写首字母

    - (NSString *)firstCharactor:(NSString *)aString {   
        // 转成可变数组   
         NSMutableString *str = [NSMutableString stringWithString:aString];  
        // 先转位带声调的拼音  
        CFStringTransform((CFMutableStringRef) str, NULL, kCFStringTransformMandarinLatin, NO);     
        // 再转换为不带声调的拼音    
        CFStringTransform((CFMutableStringRef) str, NULL, kCFStringTransformStripDiacritics, NO);   
        // 转化为大写字母   
         NSString *pinYin = [str capitalizedString];   
        // 获取并返回首字母   
         return [pinYin substringFromIndex:1];}c
    

    cell自适应高度,计算label的高低

    + (CGSize)sizeOfString:(NSString *)string withFont:(UIFont *)font width:(CGFloat)width {
        if ([NSNull null] == (id) string)
            return CGSizeZero;
        CGRect aframe = [string boundingRectWithSize:CGSizeMake(width, 0)
                                             options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading
                                          attributes:@{
                                                       NSFontAttributeName : font
                                                       } context:nil];
        return aframe.size;
    }
    

    <Masony使用时要注意先添加到superView上>

    1、Masony使用时要注意先添加到superView上
    2、Masony中得block注意循环引用
    

    手机号验证

    - (BOOL)isMobileNumber:(NSString *)mobileNum {
        
        //    电信号段:133/153/180/181/189/177
        //    联通号段:130/131/132/155/156/185/186/145/176
        //    移动号段:134/135/136/137/138/139/150/151/152/157/158/159/182/183/184/187/188/147/178
        //    虚拟运营商:170
        
        NSString *MOBILE = @"^1(3[0-9]|4[57]|5[0-35-9]|8[0-9]|7[06-8])\\d{8}$";
        
        NSPredicate *regextestmobile = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", MOBILE];
        
        return [regextestmobile evaluateWithObject:mobileNum];
    }
    

    银行卡号验证

    /*银行卡号判断*/
    + (BOOL)checkCardNo:(NSString *)cardNo{
        if (cardNo.length <= 0) {
            return NO;
        }
        int oddsum = 0;     //奇数求和
        int evensum = 0;    //偶数求和
        int allsum = 0;
        int cardNoLength = (int)[cardNo length];
        int lastNum = [[cardNo substringFromIndex:cardNoLength-1] intValue];
        cardNo = [cardNo substringToIndex:cardNoLength - 1];
        for (int i = cardNoLength -1 ; i>=1;i--) {
            NSString *tmpString = [cardNo substringWithRange:NSMakeRange(i-1, 1)];
            int tmpVal = [tmpString intValue];
            if (cardNoLength % 2 ==1 ) {
                if((i % 2) == 0){
                    tmpVal *= 2;
                    if(tmpVal>=10)
                        tmpVal -= 9;
                    evensum += tmpVal;
                }else{
                    oddsum += tmpVal;
                }
            }else{
                if((i % 2) == 1){
                    tmpVal *= 2;
                    if(tmpVal>=10)
                        tmpVal -= 9;
                    evensum += tmpVal;
                }else{
                    oddsum += tmpVal;
                }
            }
        }
        allsum = oddsum + evensum;
        allsum += lastNum;
        if((allsum % 10) == 0)
            return YES;
        else
            return NO;
    }
    

    拨打手机

    NSURL*url = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@",@"telprompt://", number]];
    [[UIApplication sharedApplication]openURL:url];
    

    查看隐藏文件

    ls -la
    

    图片截取

        CGImageRef imageRef = CGImageCreateWithImageInRect([self.originalImage CGImage], Rect);
        UIImage *smallImage = [UIImage imageWithCGImage:imageRef];
        CGImageRelease(imageRef);
    

    模态出一个可以半透明的controller

    将此控制器的背景色清空 clearcolor, 然后再上面加载一个半透明的view即可

     SharePersonCardViewController *sharePersonCardController = [[SharePersonCardViewController alloc] init];
            sharePersonCardController.modalPresentationStyle = UIModalPresentationOverCurrentContext;
            sharePersonCardController.modalPresentationStyle = UIModalPresentationOverFullScreen;
            [self presentViewController:sharePersonCardController animated:NO completion:nil];
    

    MD5加密

    - (NSString*)md5
    {
        const char *original_str = [self UTF8String];
        unsigned char result[CC_MD5_DIGEST_LENGTH];
        CC_MD5(original_str, @(strlen(original_str)).unsignedIntValue, result);
        NSMutableString *hash = [NSMutableString string];
        for (int i = 0; i < 16; i++)
            [hash appendFormat:@"%02X", result[i]];
        return [hash lowercaseString];
    }
    

    pch文件绝对路径

    $(SRCROOT)/+工程名字+PrefixHeader.pch(这个文件名)
    

    引入的第三方文件删除后,残留有警告解决方案:

    选中工程—》build Settings —>Framework Search Paths  中把残留的给删除即可
    

    将导航条的title颜色设置白色

     NSDictionary *dict = [NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:NSForegroundColorAttributeName];
    self.navigationController.navigationBar.titleTextAttributes = dict;
    

    ** 上传截图尺寸**

    iphone4 : 640x960 或者 960x640
    phone5    640 x 1136或者1136 x 640 
    phone6  750 x 1334 或者1334 x 750
    phone6 plus 1242 x 2208 或者  2208x1242
    

    上传证书无效

    打开钥匙串—》将过期的整数删除—》在Apple PKI网页下载最新的证书:(https://developer.apple.com/certificationauthority/AppleWWDRCA.cer) ,双击导入即可。
    

    检测机型和系统

    #define UIScreenWidth CGRectGetWidth([[UIScreen mainScreen] bounds])
    
    #define UIScreenHeight CGRectGetHeight([[UIScreen mainScreen] bounds])
    
    #define IS_IPHONE_4  ( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )480  ) < DBL_EPSILON  )
    
    #define IS_IPHONE_5  ( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )568  ) < DBL_EPSILON  )
    
    #define IS_IPHONE_6  ( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )667  ) < DBL_EPSILON  )
    
    #define IS_IPHONE_6P ( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )736 ) < DBL_EPSILON  )
    
    #define isIOS7 ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7)
    
    #define isIOS9 ([[[UIDevice currentDevice] systemVersion] floatValue] >= 9)
    
    #define equalIOS7 ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7 && [[[UIDevice currentDevice] systemVersion] floatValue] < 8)
    
    //检查系统版本
    #define SYSTEM_VERSION_EQUAL_TO(v)                  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
    #define SYSTEM_VERSION_GREATER_THAN(v)              ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
    #define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
    #define SYSTEM_VERSION_LESS_THAN(v)                 ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
    #define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v)     ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)
    

    宏定义

    //当前app版本
    #define JAppVersion [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]
    
    //系统目录
    #define JDocuments  [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject]
    #define JCaches [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject]
    
    //当前系统版本
    #define JSystenVersion [[[UIDevice currentDevice]systemVersion] floatValue]
    #define iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136),[[UIScreen mainScreen] currentMode].size) : NO)
    //重置图片大小
    #define JSTRETCH_IMAGE(image, edgeInsets) (JSystenVersion <</span> 6.0 ? [image stretchableImageWithLeftCapWidth:edgeInsets.left topCapHeight:edgeInsets.top] : [image resizableImageWithCapInsets:edgeInsets resizingMode:UIImageResizingModeStretch])
    
    //----------方法简写-------
    #define JScreenWidth ([UIScreen mainScreen].bounds.size.width)
    #define JScreenHeight ([UIScreen mainScreen].bounds.size.height)
    #define JUserDefaults       [NSUserDefaults standardUserDefaults]
    #define JNotificationCenter [NSNotificationCenter defaultCenter]
    //block self
    #define WEAKSELF typeof(self) __weak weakSelf = self;
    #define STRONGSELF typeof(weakSelf) __strong strongSelf = weakSelf;
    //颜色
    #define RGBA(r,g,b,a) [UIColor colorWithRed:r/255.f green:g/255.f blue:b/255.f alpha:a]
    #define RGB(r,g,b) [UIColor colorWithRed:r/255.f green:g/255.f blue:b/255.f alpha:1]
    //字体
    #define WFONT_BOLD(_size_) [UIFont fontWithName:@"HelveticaNeue-Bold" size:_size_]
    #define WFONT(_size_) [UIFont fontWithName:@"HelveticaNeue" size:_size_]
    #define dispatch_main_sync_safe(block)\
    if ([NSThread isMainThread])\
    {\
    block();\
    }\
    else\
    {\
    dispatch_sync(dispatch_get_main_queue(), block);\
    }
    //调试
    #ifdef DEBUG
    #define NSLog(...) NSLog(__VA_ARGS__)
    #else
    #define NSLog(...)
    #endif
    

    UIColor 分类

    #import "UIColor+Hex.h"
    
    @implementation UIColor (Hex)
    
    + (UIColor *)colorWithHex:(NSInteger)hexValue alpha:(CGFloat)alphaValue {
     return [UIColor colorWithRed:((float) ((hexValue & 0xFF0000) >> 16)) / 255.0
             green:((float) ((hexValue & 0xFF00) >> 8)) / 255.0
           blue:((float) (hexValue & 0xFF)) / 255.0
             alpha:alphaValue];
    }
    
    + (UIColor *)colorWithHex:(NSInteger)hexValue {
     return [UIColor colorWithHex:hexValue alpha:1.0];
    }
    
    

    collectionView 默认选中

    _indexpath = [NSIndexPath indexPathForRow:0 inSection:0 ];
        [collectionView selectItemAtIndexPath:_indexpath animated:YES scrollPosition:(UICollectionViewScrollPositionTop)];
    }
    
    - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
        return _arr.count;
    }
    
    // The cell that is returned must be retrieved from a call to -dequeueReusableCellWithReuseIdentifier:forIndexPath:
    - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
        CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
        cell.label.text = _arr[indexPath.item];
        if (cell.isSelected) {
            cell.label.backgroundColor = [UIColor grayColor];
            cell.line.backgroundColor = [UIColor redColor];
        } else {
            cell.label.backgroundColor = [UIColor whiteColor];
            cell.line.backgroundColor = [UIColor whiteColor];
    
        }
        
        return cell;
    }
    
    - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
        NSLog(@"---%ld---",indexPath.item);
        CollectionViewCell *cell = (CollectionViewCell *)[collectionView cellForItemAtIndexPath:indexPath];
        [self updateCellStatus:cell selected:YES];
        
    }
    
    -(void)updateCellStatus:(CollectionViewCell *)cell selected:(BOOL)selected {
        
        
        if (selected == YES) {
            cell.label.backgroundColor = [UIColor grayColor];
            cell.line.backgroundColor = [UIColor redColor];
        }
        if (selected == NO) {
            cell.label.backgroundColor = [UIColor whiteColor];
            cell.line.backgroundColor = [UIColor whiteColor];
        }
        
    }
    
    - (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath {
        CollectionViewCell *cell = (CollectionViewCell *)[collectionView cellForItemAtIndexPath:indexPath];
        [self updateCellStatus:cell selected:NO];
        
    }
    

    相关文章

      网友评论

          本文标题:知识点

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