一、数组去重的最简单方法:git
NSArray *arr = @[@"aa",@"aa",@"bb"]; arr = [arr valueForKeyPath:@"@distinctUnionOfObjects.self"]; kDLOG(@"%@",arr);
获得的即为去重后的数组,并且顺序不变。github
数组排序:web
//按字母顺序排序,其中keys为要进行排序的字典 NSArray *sortedArray = [keys sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) { return [obj1 compare:obj2 options:NSNumericSearch]; }];
二、改变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();
三、判断屏幕局尺寸是否是5json
#define iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)
一个宏即搞定。windows
四、将数组或者字典转化成json数组
有时候上传数据的时候,要用到json来上传,这个时候封装一个方法,传进去一个字典或者数据,出来就是一个json是否是很爽,so:cookie
#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]; }
五、动态获取字符串的range网络
通常状况下获取一个字符串中的某个特定的字符串的range采用app
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;
其效果图为:
六、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]; }
七、根据时间戳返回一个时间字符串:
封装了一下几种,能够根据须要拿来使用,固然格式也是能够本身修改的:
#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]; }
八、根据颜色生成图片
这个就不用解释了,直接上代码:
#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; }
九、判断字符串是否为空
这是我认为相对来讲比较全面的判断字符串为空的方法:
#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; }
十、动态计算字符串的高度
这个用处就比较大了,速度收藏:
#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;//返回 计算出得行高 } }
十一、获取iOS版本号
+ (double)getCurrentIOS { return [[[UIDevice currentDevice] systemVersion] doubleValue]; }
十二、点击空白收键盘,适用于全部能够编辑的控件
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ //关闭键盘的方法 [[[UIApplication sharedApplication] keyWindow] endEditing:YES]; }
1三、解决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;
1四、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];
1五、设置图片为当前的背景
//设置图片为当前controller的背景色 self.view.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"backImageplus"]]; //解决图片不居中的问题 self.view.layer.contents=(__bridge id _Nullable)[UIImage imageNamed:@"backImageplus"].CGImage;
1六、设置button上的字体左对齐
button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; button.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
其实只须要第一行代码就能够了,只是设置第一行后字体会牢牢贴着按钮的边界,不怎么美观,因此能够设置edgeInsets.
1七、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里面,你们可根据须要进行相应的提取与拼接。
1八、成员变量、实例变量与基本数据类型变量
以下图:
凡是在@interface 括号里面的统称为“成员变量”,它包括实例变量和基本数据类型变量,也便是:
成员变量 = 实例变量 + 基本数据类型变量。
值得一提的是在类方法中,成员变量是不容许被使用的。
1九、数组排序
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: http://goshdarnblocksyntax.com/(详情请戳)
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:该图片引自:http://blog.ibireme.com/2013/11/27/objc-block/
2一、gitignore须要添加的额忽略内容
.DS_Store */build/* *.pbxuser !default.pbxuser *.mode1v3 !default.mode1v3 *.mode2v3 !default.mode2v3 *.perspectivev3 !default.perspectivev3 *.xcuserdatad *.xcuserstate xcuserdata profile *.moved-aside DerivedData .idea/ *.hmap
2二、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 ,用于保存一些网页,以便于在无网络的时候也能访问。
2三、修改相机和相册界面的文字为中文
只须要将plist中的Localization native development region 的en修改为China
2四、实用库
将此库导入到工程中便可实现收键盘的效果,不再用逐个页面去写了:
https://github.com/hackiftekhar/IQKeyboardManager
2五、经过消息响应者链找到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; } }
2六、消除系统的deprecated警告
#pragma clang diagnostic push #pragma clang diagnostic ignored"-Wdeprecated-declarations" //写系统会给咱们deprecated警告的代码 #pragma clang diagnostic pop
2七、得到当前显示界面的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 }
2八、添加子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 著做权归做者全部,转载请联系做者得到受权,并标注“简书做者”。
2九、判断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;
3一、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
3二、mac破解开机密码:
一、长按 command + s 进入命令行 二、fsck -y 三、mount -uaw 四、rm/var/db/.AppleSetupDone 五、reboot
3三、网络图片测试用:
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" ];
3四、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]]; }
3五、iOS对小数四舍五入:
CGFloat num = 5.567; NSLog(@"%.2f",num); //其实当咱们直接去保留几位小数的时候,系统已经帮咱们自动去处理了(四舍五入),看到网上有部分童靴弄了一堆算法来计算这个四舍五入,彻底是没不要的,不是吗?
3六、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); }
3七、夜间模式:
//最好用的第三方: DKNightVersion 使用方法: 一、#import <DKNightVersion/DKNightVersion.h> 二、self.view.dk_backgroundColorPicker = DKColorPickerWithKey(BG); 三、在须要改变主题模式的地方调用: DKNightVersionManager *manager = [DKNightVersionManager sharedManager]; manager.themeVersion = DKThemeVersionNight;
3八、快捷键
option + command + [ 或 ] 将选中的代码向上或者向下移动
3九、调试:
thread info 命令能够查看当前断点线程的信息,若是再加上一个数字参数表示查看某个线程号的信息 thread backtrace 能够查看调用栈。