知识点

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

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];
    
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 214,444评论 6 496
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 91,421评论 3 389
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 160,036评论 0 349
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 57,363评论 1 288
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 66,460评论 6 386
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 50,502评论 1 292
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,511评论 3 412
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,280评论 0 270
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,736评论 1 307
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,014评论 2 328
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,190评论 1 342
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,848评论 5 338
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,531评论 3 322
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,159评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,411评论 1 268
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,067评论 2 365
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,078评论 2 352

推荐阅读更多精彩内容