1、数组去重的最简单方法:
NSArray *arr = @[@"aa",@"aa",@"bb"]; arr = [arr valueForKeyPath:@"@distinctUnionOfObjects.self"]; kDLOG(@"%@",arr);
得到的即为去重后的数组,而且顺序不变。
数组排序:
//按字母顺序排序,其中keys为要进行排序的字典 NSArray *sortedArray = [keys sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) { return [obj1 compare:obj2 options:NSNumericSearch]; }];
2、改变cell自带imageView的大小
//cell自带的imgeView是只读属性,要改变大小需要重绘 CGSize itemSize = CGSizeMake(50, 50); UIGraphicsBeginImageContext(itemSize); CGRect imageRect = CGRectMake(0.0, 0.0, itemSize.width, itemSize.height); [cell.imageView.image drawInRect:imageRect]; cell.imageView.image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext();
3、判断屏幕局尺寸是不是5
#define iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)
一个宏即搞定。
4、将数组或者字典转化成json
有时候上传数据的时候,要用到json来上传,这个时候封装一个方法,传进去一个字典或者数据,出来就是一个json是不是很爽,so:
#pragma mark - 将数组或字典转化成json+ (NSString*)objectToJson:(id )object{ NSError *parseError = nil; //NSJSONWritingPrettyPrinted 是有换位符的。 //如果NSJSONWritingPrettyPrinted 是nil 的话 返回的数据是没有 换位符的 NSData *jsonData = [NSJSONSerialization dataWithJSONObject:object options:NSJSONWritingPrettyPrinted error:&parseError]; if (parseError) { kDLOG(@"转化失败:%@",parseError); } return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; }
5、动态获取字符串的range
一般情况下获取一个字符串中的某个特定的字符串的range采用
NSRangeFromString(@"hello");
这种形式即可,但大多数情况下,我们需要用的数据都是从后台获取的,这时再用这种方法就获取不到了,需采用下面这种形式:
NSRange range2 = [integralString rangeOfString:[NSString stringWithFormat:@"%@",model.rule_score] options:NSBackwardsSearch];
而获取range最常用的地方就是使用富文本时对不同的字符串使用不同的字体颜色及大小,在粘贴一段项目中用到的富文本:
//从后台获取的字符串,加上定制的“获得” NSString *integralString = [NSString stringWithFormat:@"%@获得%@",model.rule_action_desc,model.rule_score]; //创建富文本 NSMutableAttributedString *attributedStr = [[NSMutableAttributedString alloc] initWithString:integralString]; //设置字体大小 [attributedStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:13.0] range:NSMakeRange(0, attributedStr.string.length)]; //分别获得想要改变字体颜色的range NSRange range1 = [integralString rangeOfString:[NSString stringWithFormat:@"%@获得",model.rule_action_desc] options:NSBackwardsSearch]; NSRange range2 = [integralString rangeOfString:[NSString stringWithFormat:@"%@",model.rule_score] options:NSBackwardsSearch]; //改变字体颜色 [attributedStr addAttribute:NSForegroundColorAttributeName value:UIColorFromRGB(0x333333) range:range1]; [attributedStr addAttribute:NSForegroundColorAttributeName value:UIColorFromRGB(0xff4c79) range:range2]; UILabel *integralScoreLabel = [[UILabel alloc] initWithFrame:CGRectMake(timeLabel.frame.origin.x + timeLabel.frame.size.width + 30, timeLabel.frame.origin.y, 120, timeLabel.frame.size.height)]; //设置label的attributedText integralScoreLabel.attributedText = attributedStr;
其效果图为:
6、RGB颜色值转化
相信只要做app就一定会用到:
先来一个最方面最简单的方法:#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]使用的时候直接: view.backgroundColor = UIColorRGB(0x333333);so easy!或者:#define rgb(r,g,b) [UIColor colorWithRed:r/255.0f green:g/255.0f blue:b/255.0f alpha:1.0f]#define rgba(r,g,b,a) [UIColor colorWithRed:r/255.0f green:g/255.0f blue:b/255.0f alpha:a]使用: self.backgroundColor = rgba(0, 0, 0, .5f);
当然这种方法也是可以的,看着很长,用着也很简单:#pragma mark - RGB颜色值转换+(UIColor *) colorWithHexString: (NSString *) hexString { NSString *colorString = [[hexString stringByReplacingOccurrencesOfString: @"#" withString: @""] uppercaseString]; CGFloat alpha, red, blue, green; switch ([colorString length]) { case 3: // #RGB alpha = 1.0f; red = [self colorComponentFrom: colorString start: 0 length: 1]; green = [self colorComponentFrom: colorString start: 1 length: 1]; blue = [self colorComponentFrom: colorString start: 2 length: 1]; break; case 4: // #ARGB alpha = [self colorComponentFrom: colorString start: 0 length: 1]; red = [self colorComponentFrom: colorString start: 1 length: 1]; green = [self colorComponentFrom: colorString start: 2 length: 1]; blue = [self colorComponentFrom: colorString start: 3 length: 1]; break; case 6: // #RRGGBB alpha = 1.0f; red = [self colorComponentFrom: colorString start: 0 length: 2]; green = [self colorComponentFrom: colorString start: 2 length: 2]; blue = [self colorComponentFrom: colorString start: 4 length: 2]; break; case 8: // #AARRGGBB alpha = [self colorComponentFrom: colorString start: 0 length: 2]; red = [self colorComponentFrom: colorString start: 2 length: 2]; green = [self colorComponentFrom: colorString start: 4 length: 2]; blue = [self colorComponentFrom: colorString start: 6 length: 2]; break; default: [NSException raise:@"Invalid color value" format: @"Color value %@ is invalid. It should be a hex value of the form #RBG, #ARGB, #RRGGBB, or #AARRGGBB", hexString]; break; } return [UIColor colorWithRed: red green: green blue: blue alpha: alpha];}
7、根据时间戳返回一个时间字符串:
封装了一下几种,可以根据需要拿来使用,当然格式也是可以自己修改的:
#pragma mark - 年月日字符串+(NSString *)timeYMDStringFrom:(double )time{ NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init] ; //dateFormatter.timeZone = [NSTimeZone timeZoneWithName:@"shanghai"]; [dateFormatter setDateFormat:@"YYYY.MM.dd"]; NSDate *timeDate = [NSDate dateWithTimeIntervalSince1970:time/1000.0f]; return [dateFormatter stringFromDate:timeDate];}#pragma mark - 小时分字符串+(NSString *)timeHMStringFrom:(double )time{ NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init] ; //dateFormatter.timeZone = [NSTimeZone timeZoneWithName:@"shanghai"]; [dateFormatter setDateFormat:@"HH:mm"]; NSDate *timeDate = [NSDate dateWithTimeIntervalSince1970:time/1000.0f]; return [dateFormatter stringFromDate:timeDate];}#pragma mark - 月日字符串+(NSString *)timeMDStingFrom:(double )time{ NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; //dateFormatter.timeZone = [NSTimeZone timeZoneWithName:@"shanghai"]; [dateFormatter setDateFormat:@"MM月dd日"]; NSDate *timeDate = [NSDate dateWithTimeIntervalSince1970:time/1000.0f]; return [dateFormatter stringFromDate:timeDate];}
8、根据颜色生成图片
这个就不用解释了,直接上代码:
#pragma mark - 根据颜色生成图片+ (UIImage *)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;}
9、判断字符串是否为空
这是我认为相对来说比较全面的判断字符串为空的方法:
#pragma mark - 判断字符串是否为空+(BOOL)isBlankString:(NSString *)string{ if (string == nil || string == NULL) { return YES; } if ([string isKindOfClass:[NSNull class]]) { return YES; } if ([[string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length]==0) { return YES; } return NO;}
10、动态计算字符串的高度
这个用处就比较大了,速度收藏:
#pragma mark - 动态计算字符串的高度+ (CGFloat)textHeightFromTextString:(NSString *)text width:(CGFloat)textWidth fontSize:(CGFloat)size{ if ([Tools getCurrentIOS] >= 7.0) { //iOS7之后 /* 第一个参数: 预设空间 宽度固定 高度预设 一个最大值 第二个参数: 行间距 如果超出范围是否截断 第三个参数: 属性字典 可以设置字体大小 */ NSDictionary *dict = @{NSFontAttributeName:[UIFont systemFontOfSize:size]}; CGRect rect = [text boundingRectWithSize:CGSizeMake(textWidth, MAXFLOAT) options:NSStringDrawingTruncatesLastVisibleLine|NSStringDrawingUsesFontLeading|NSStringDrawingUsesLineFragmentOrigin attributes:dict context:nil]; //返回计算出的行高 return rect.size.height; }else { //iOS7之前 /* 1.第一个参数 设置的字体固定大小 2.预设 宽度和高度 宽度是固定的 高度一般写成最大值 3.换行模式 字符换行 */ CGSize textSize = [text sizeWithFont:[UIFont systemFontOfSize:size] constrainedToSize:CGSizeMake(textWidth, MAXFLOAT) lineBreakMode:NSLineBreakByCharWrapping]; return textSize.height;//返回 计算出得行高 }}
11、获取iOS版本号
+ (double)getCurrentIOS { return [[[UIDevice currentDevice] systemVersion] doubleValue];}
12、点击空白收键盘,适用于所有可以编辑的控件
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ //关闭键盘的方法 [[[UIApplication sharedApplication] keyWindow] endEditing:YES];}
13、解决cell分割线不能从头开始
当然,不想这么麻烦的话完全可以自己定制,这里只是提供一个思路而已,把下面这两个方法扔到tableView的界面,修改相应的tableView即可:
-(void)viewDidLayoutSubviews { if ([tableView respondsToSelector:@selector(setSeparatorInset:)]) { [tableView setSeparatorInset:UIEdgeInsetsZero]; } if ([tableView respondsToSelector:@selector(setLayoutMargins:)]) { [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]; }}
其中第一个方法是在controller里面才有效的,那如果不是在controller里面写这些方法的话,在创建tableView的时候可以这样来:
tableView.separatorInset = UIEdgeInsetsZero; tableView.layoutMargins = UIEdgeInsetsZero;
14、tableView的局部刷新
我们在用tableView时最习惯用的、也是写起来最顺手的就是[tableView reloadData] ,但是对于数据量比较大、复杂的tableView,这样做事相当耗性能的,所以能用局部刷新的就用局部刷新,以提高性能:
//局部section刷新 NSIndexSet *set=[[NSIndexSet alloc]initWithIndex:1];//刷新第二个section [tableView reloadSections:set withRowAnimation:UITableViewRowAnimationAutomatic];//局部cell刷新 NSIndexPath *indexpath=[NSIndexPath indexPathForRow:2 inSection:0];//刷新第0个section的第3行 [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationMiddle];
15、设置图片为当前的背景
//设置图片为当前controller的背景色 self.view.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"backImageplus"]];//解决图片不居中的问题 self.view.layer.contents=(__bridge id _Nullable)[UIImage imageNamed:@"backImageplus"].CGImage;
16、设置button上的字体左对齐
button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; button.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
其实只需要第一行代码就可以了,只是设置第一行后字体会紧紧贴着按钮的边界,不怎么美观,所以可以设置edgeInsets.
17、WKWebView添加cookie
其实所有的要添加cookie的网络请求包括web,最终都是要在request上添加,如下:
web = [[WKWebView alloc] initWithFrame:CGRectMake(0, 64, kScreen_width, kScreen_height - 64)]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]]; NSString *cookie = [Tools readCurrentCookie]; [request addValue:cookie forHTTPHeaderField:@"Cookie"]; [web loadRequest:request];
其中获得cookie的信息我封装了一下:
+(NSString *)readCurrentCookie{ NSHTTPCookieStorage*cookieJar = [NSHTTPCookieStorage sharedHTTPCookieStorage]; NSMutableString *cookieString = [[NSMutableString alloc] init]; NSMutableString *domain = [[NSMutableString alloc] initWithString:kBaseUrl_New]; NSArray *domainArr = [domain componentsSeparatedByString:@":"]; NSMutableString *domainString = [NSMutableString stringWithString:domainArr[1]]; [domainString deleteCharactersInRange:NSMakeRange(0, 2)]; NSHTTPCookie *currentCookie= [[NSHTTPCookie alloc] init]; for (NSHTTPCookie*cookie in [cookieJar cookies]) { kDLOG(@"cookie:%@", cookie); if ([cookie.domain isEqualToString:domainString]) { currentCookie = cookie; [cookieString appendFormat:@"%@=%@",cookie.name,cookie.value]; } } return cookieString;}
在这里,由于app用到了两个后台,应用中保存了两个cookie,所以我根据baseUrl来和domain来进行匹配,用以判断哪一个是我们所需要的cookie,进而提取出我们需要的信息,而提取的信息则根据后台的需要去拼接,在本例中只用到了那么和value,所以只提取出这些信息,添加到了web的cookie里面,大家可根据需要进行相应的提取与拼接。
18、成员变量、实例变量与基本数据类型变量
如下图:
凡是在 括号里面的统称为“成员变量”,它包括实例变量和基本数据类型变量,也即是:
成员变量 = 实例变量 + 基本数据类型变量。
值得一提的是在类方法中,成员变量是不允许被使用的。
19、数组排序
NSArray *stringArray = [NSArray arrayWithObjects:@"abc 1", @"abc 21", @"abc 12",@"abc 13",@"abc 05",nil]; NSComparator sortBlock = ^(id string1, id string2){ return [string1 compare:string2]; }; NSArray *sortArray = [stringArray sortedArrayUsingComparator:sortBlock]; NSLog(@"sortArray:%@", sortArray);
运行结果:
sortArray:( "abc 05", "abc 1", "abc 12", "abc 13", "abc 21")
20、小记一下block: (详情请戳)
How Do I Declare A Block in Objective-C?As a local variable: returnType (^blockName)(parameterTypes) = ^returnType(parameters) {...}; As a property: @property (nonatomic, copy, nullability) returnType (^blockName)(parameterTypes); As a method parameter: - (void)someMethodThatTakesABlock:(returnType (^nullability)(parameterTypes))blockName; As an argument to a method call: [someObject someMethodThatTakesABlock:^returnType (parameters) {...}]; As a typedef: typedef returnType (^TypeName)(parameterTypes); TypeName blockName = ^returnType(parameters) {...};
PS:该图片引自:
21、gitignore需要添加的额忽略内容
.DS_Store*/build/**.pbxuser!default.pbxuser*.mode1v3!default.mode1v3*.mode2v3!default.mode2v3*.perspectivev3!default.perspectivev3*.xcuserdatad*.xcuserstatexcuserdataprofile*.moved-asideDerivedData.idea/*.hmap
22、mac下的一些小命令
<1> 应用进程窗口:command + option +esc
<2> 不显示系统的隐藏文件:defaults write com.apple.finder AppleShowAllFiles NO(需要重启finder)
显示系统的隐藏文件: defaults write com.apple.finder AppleShowAllFiles YES(需要重启finder)
重启finder :(1)鼠标放到finder上,按住option,鼠标右键,会出现重启finder字样
(2)打开应用进程,找到finder,重启
<3> 离保存网页:command + s ,用于保存一些网页,以便于在无网络的时候也能访问。
23、修改相机和相册界面的文字为中文
只需要将plist中的Localization native development region 的en修改成China
24、实用库
将此库导入到工程中即可实现收键盘的效果,再也不用逐个页面去写了:
25、通过消息响应者链找到UIView所在的UIViewController
- (UIViewController *) firstViewController { // convenience function for casting and to "mask" the recursive function return (UIViewController *)[self traverseResponderChainForUIViewController];} - (id) traverseResponderChainForUIViewController { id nextResponder = [self nextResponder]; if ([nextResponder isKindOfClass:[UIViewController class]]) { return nextResponder; } else if ([nextResponder isKindOfClass:[UIView class]]) { return [nextResponder traverseResponderChainForUIViewController]; } else { return nil; }}
26、消除系统的deprecated警告
#pragma clang diagnostic push#pragma clang diagnostic ignored"-Wdeprecated-declarations" //写系统会给我们deprecated警告的代码 #pragma clang diagnostic pop
27、获得当前显示界面的controller
//提供两种方式-(UIViewController *) getcurrentViewController{#if 0 UIWindow *window = [[UIApplication sharedApplication] windows].lastObject; UIView *frontView = [window subviews][0]; id nextResponder = [frontView nextResponder]; if ([nextResponder isKindOfClass:[UIViewController class]]) { return nextResponder; }else{ return window.rootViewController; }#else UIWindow *window = [[UIApplication sharedApplication] windows].lastObject; return ((UINavigationController *)window.rootViewController).visibleViewController; UIViewController * currVC = nil; UIViewController * Rootvc = window.rootViewController ; do { if ([Rootvc isKindOfClass:[UINavigationController class]]) { UINavigationController * nav = (UINavigationController *)Rootvc; UIViewController * v = [nav.viewControllers lastObject]; currVC = v; Rootvc = v.presentedViewController; continue; }else if([Rootvc isKindOfClass:[UITabBarController class]]){ UITabBarController * tabVC = (UITabBarController *)Rootvc; currVC = tabVC; Rootvc = [tabVC.viewControllers objectAtIndex:tabVC.selectedIndex]; continue; } } while (Rootvc!=nil); return currVC;#endif}
28、添加子controller
//添加子controller的正确方式[self addChildViewController:newVC];//[newVC willMoveToParentViewController:self];//这句代码为隐式调用[self.view addSubview:newVC.view];[newVC didMoveToParentViewController:self];//移除子controller[oldVC willMoveToParentViewController:nil];[oldVC.view removeFromSuperview];[oldVC removeFromParentViewController]; //[oldVC didMoveToParentViewController:nil];文/KevinLee(简书作者)原文链接:http://www.jianshu.com/p/99f37dac2e8c著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”。
29、判断scrollview的滚动方向
-(BOOL )isScrolltoLeft:(UIScrollView *) scrollView{ BOOL ret = NO; static CGFloat newX = 0; static CGFloat oldX = 0; newX = scrollView.contentOffset.x; if (newX > oldX) { ret = NO; }else{ ret = YES; } oldX = newX; return ret;}#pragma mark - 判断滚动方向-(BOOL )isScrolltoLeft:(UIScrollView *) scrollView{ //返回YES为向左反动,NO为右滚动 if ([scrollView.panGestureRecognizer translationInView:scrollView.superview].x < 0) { return YES; }else{ return NO; }}
30、alpha与backgroundColor的alpha
//这样的话,将只改变view的透明度,而不会影响子控件的透明度 view.backgroundColor = [self.backgroundColor colorWithAlphaComponent:0.5]; //这样设置,是view及其子控件都将出现透明效果 view.alpha = 0.5;
31、NS_ENUM 与 NS_OPTION
typedef NS_ENUM(NSInteger, LoginState) { LoginSuccess, loginFailed,};typedef NS_OPTIONS(NSInteger, Direction) { DirectionTop =0, DirectionLeft = 1 << 0, DirectionBottom = 2 << 0, DirectionRight = 3 << 0,};
使用NS_OPTION可以使用位运算,如:
DirectionTop | DirectionBottom | DirectionLeft
32、mac破解开机密码:
1、长按 command + s 进入命令行2、fsck -y3、mount -uaw4、rm/var/db/.AppleSetupDone5、reboot
33、网络图片测试用:
NSArray *networkImages=@[ @"http://www.netbian.com/d/file/20150519/f2897426d8747f2704f3d1e4c2e33fc2.jpg", @"http://www.netbian.com/d/file/20130502/701d50ab1c8ca5b5a7515b0098b7c3f3.jpg", @"http://www.netbian.com/d/file/20110418/48d30d13ae088fd80fde8b4f6f4e73f9.jpg", @"http://www.netbian.com/d/file/20150318/869f76bbd095942d8ca03ad4ad45fc80.jpg", @"http://www.netbian.com/d/file/20110424/b69ac12af595efc2473a93bc26c276b2.jpg", @"http://www.netbian.com/d/file/20140522/3e939daa0343d438195b710902590ea0.jpg", @"http://www.netbian.com/d/file/20141018/7ccbfeb9f47a729ffd6ac45115a647a3.jpg", @"http://www.netbian.com/d/file/20140724/fefe4f48b5563da35ff3e5b6aa091af4.jpg", @"http://www.netbian.com/d/file/20140529/95e170155a843061397b4bbcb1cefc50.jpg" ];
34、MD5加密:
- (NSString *)MD5Hash{ const char *cStr = [self UTF8String]; unsigned char result[16]; CC_MD5(cStr, strlen(cStr), result); return [NSString stringWithFormat: @"%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X", result[0], result[1], result[2], result[3], result[4], result[5], result[6], result[7], result[8], result[9], result[10], result[11], result[12], result[13], result[14], result[15]];}
35、iOS对小数四舍五入:
CGFloat num = 5.567; NSLog(@"%.2f",num);//其实当我们直接去保留几位小数的时候,系统已经帮我们自动去处理了(四舍五入),看到网上有部分童靴弄了一堆算法来计算这个四舍五入,完全是没不要的,不是吗?
36、scrollView放大图片:
-(void)createScrollView{ _scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)]; _scrollView.minimumZoomScale = 0.1; _scrollView.maximumZoomScale = 5; _scrollView.pagingEnabled = YES; //添加图片控件 UIImage *image=[UIImage imageNamed:@"myIcon.jpg"]; _imageView=[[UIImageView alloc]initWithImage:image]; _imageView.frame = CGRectMake(0, 0, _imageView.image.size.width, _imageView.image.size.height); [_scrollView addSubview:_imageView]; self.scrollView.delegate = self; [self.view addSubview:self.scrollView]; }//此方法必须实现,否则scrollview将不相应放大的手势操作-(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{ return _imageView;//返回scrollview的imageView}#pragma mark 当图片小于屏幕宽高时缩放后让图片显示到屏幕中间-(void)scrollViewDidZoom:(UIScrollView *)scrollView{ CGSize originalSize=_scrollView.bounds.size; CGSize contentSize=_scrollView.contentSize; CGFloat offsetX=originalSize.width>contentSize.width?(originalSize.width-contentSize.width)/2:0; CGFloat offsetY=originalSize.height>contentSize.height?(originalSize.height-contentSize.height)/2:0; _imageView.center=CGPointMake(contentSize.width/2+offsetX, contentSize.height/2+offsetY);}
37、夜间模式:
//最好用的第三方:DKNightVersion使用方法:1、#import2、self.view.dk_backgroundColorPicker = DKColorPickerWithKey(BG);3、在需要改变主题模式的地方调用: DKNightVersionManager *manager = [DKNightVersionManager sharedManager]; manager.themeVersion = DKThemeVersionNight;
38、快捷键
option + command + [ 或 ] 将选中的代码向上或者向下移动
39、调试:
thread info 命令可以查看当前断点线程的信息,如果再加上一个数字参数表示查看某个线程号的信息thread backtrace 可以查看调用栈。