1:Masonry 2個或2個以上的控件等間隔排序網絡
/** * 多個控件固定間隔的等間隔排列,變化的是控件的長度或者寬度值 * * @param axisType 軸線方向 * @param fixedSpacing 間隔大小 * @param leadSpacing 頭部間隔 * @param tailSpacing 尾部間隔 */ - (void)mas_distributeViewsAlongAxis:(MASAxisType)axisType withFixedSpacing:(CGFloat)fixedSpacing l eadSpacing:(CGFloat)leadSpacing tailSpacing:(CGFloat)tailSpacing; /** * 多個固定大小的控件的等間隔排列,變化的是間隔的空隙 * * @param axisType 軸線方向 * @param fixedItemLength 每一個控件的固定長度或者寬度值 * @param leadSpacing 頭部間隔 * @param tailSpacing 尾部間隔 */ - (void)mas_distributeViewsAlongAxis:(MASAxisType)axisType withFixedItemLength:(CGFloat)fixedItemLength leadSpacing:(CGFloat)leadSpacing tailSpacing:(CGFloat)tailSpacing;
使用方法很簡單,由於它是NSArray的類擴展:app
// 建立水平排列圖標 arr中放置了2個或連個以上的初始化後的控件 // alongAxis 軸線方向 固定間隔 頭部間隔 尾部間隔 [arr mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedSpacing:20 leadSpacing:5 tailSpacing:5]; [arr makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(@60); make.height.equalTo(@60); }];
實例:框架
NSMutableArray *mutableArr = [[NSMutableArray alloc] initWithCapacity:6]; for (int i=0; i<3; i++) { UIButton *button = [[UIButton alloc] init]; [button setTitle:strArr[i] forState:UIControlStateNormal]; [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; button.layer.borderColor = [UIColor blackColor].CGColor; [button addTarget:self action:@selector(show:) forControlEvents:UIControlEventTouchUpInside]; button.layer.borderWidth = 2; [self addSubview:button]; [mutableArr addObject:button]; } [mutableArr mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedSpacing:20 leadSpacing:20 tailSpacing:20]; [mutableArr mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(@120); make.height.equalTo(@75); }];
2:YYLabel的簡單使用異步
NSString *title = @"不得不說 YYKit第三方框架確實很牛,YYLabel在富文本顯示和操做方面至關強大,尤爲是其異步渲染,讓界面要多流暢有多流暢,這裏咱們介紹下簡單的使用"; //YYLabel 富文本 YYLabel *titleLabel = [YYLabel new]; //異步渲染 當一個label顯示巨量文字的時候就能明顯感受到此功能的強大 titleLabel.displaysAsynchronously = YES; [self.view addSubView:titleLabel]; titleLable.numOfLines = 0; YYTextContainer *titleContarer = [YYTextContainer new]; //限制寬度 detailContarer.size = CGSizeMake(100,CGFLOAT_MAX); NSMutableAttributedString *titleAttr = [self getAttr:title]; YYTextLayout *titleLayout = [YYTextLayout layoutWithContainer:titleContarer text:titleAttr]; CGFloat titleLabelHeight = titleLayout.textBoundingSize.height; titleLabel.frame = CGRectMake(50,50,100,titleLabelHeight);
- (NSMutableAttributedString*)getAttr:(NSString*)attributedString { NSMutableAttributedString * resultAttr = [[NSMutableAttributedString alloc] initWithString:attributedString]; //對齊方式 這裏是 兩邊對齊 resultAttr.yy_alignment = NSTextAlignmentJustified; //設置行間距 resultAttr.yy_lineSpacing = 5; //設置字體大小 resultAttr.yy_font = [UIFont systemFontOfSize:CONTENT_FONT_SIZE]; //能夠設置某段字體的大小 //[resultAttr yy_setFont:[UIFont boldSystemFontOfSize:CONTENT_FONT_SIZE] range:NSMakeRange(0, 3)]; //設置字間距 //resultAttr.yy_kern = [NSNumber numberWithFloat:1.0]; return resultAttr; }
3:appStore版本號檢測及更新實例async
//1必定要先配置本身項目在商店的APPID,配置完最好在真機上運行才能看到徹底效果哦! #define STOREAPPID @"1104867082" @interface ViewController () @end @implementation ViewController * 天朝專用檢測app更新 */ -(void)hsUpdateApp { //2先獲取當前工程項目版本號 NSDictionary *infoDic=[[NSBundle mainBundle] infoDictionary]; NSLog(@"%@",infoDic); NSString *currentVersion=infoDic[@"CFBundleShortVersionString"]; //3從網絡獲取appStore版本號 NSError *error; NSData *response = [NSURLConnection sendSynchronousRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://itunes.apple.com/cn/lookup?id=%@",STOREAPPID]]] returningResponse:nil error:nil]; if (response == nil) { NSLog(@"你沒有鏈接網絡哦"); return; } NSDictionary *appInfoDic = [NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableLeaves error:&error]; if (error) { NSLog(@"hsUpdateAppError:%@",error); return; } // NSLog(@"%@",appInfoDic); NSArray *array = appInfoDic[@"results"]; if (array.count < 1) { NSLog(@"此APPID爲未上架的APP或者查詢不到"); return; } NSDictionary *dic = array[0]; NSString *appStoreVersion = dic[@"version"]; //打印版本號 NSLog(@"當前版本號:%@\n商店版本號:%@",currentVersion,appStoreVersion); //設置版本號 currentVersion = [currentVersion stringByReplacingOccurrencesOfString:@"." withString:@""]; if (currentVersion.length==2) { currentVersion = [currentVersion stringByAppendingString:@"0"]; }else if (currentVersion.length==1){ currentVersion = [currentVersion stringByAppendingString:@"00"]; } appStoreVersion = [appStoreVersion stringByReplacingOccurrencesOfString:@"." withString:@""]; if (appStoreVersion.length==2) { appStoreVersion = [appStoreVersion stringByAppendingString:@"0"]; }else if (appStoreVersion.length==1){ appStoreVersion = [appStoreVersion stringByAppendingString:@"00"]; } //4當前版本號小於商店版本號,就更新 if([currentVersion floatValue] < [appStoreVersion floatValue]) { UIAlertController *alercConteoller = [UIAlertController alertControllerWithTitle:@"版本有更新" message:[NSString stringWithFormat:@"檢測到新版本(%@),是否更新?",dic[@"version"]] preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *actionYes = [UIAlertAction actionWithTitle:@"更新" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { //此處加入應用在app store的地址,方便用戶去更新,一種實現方式以下 NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://itunes.apple.com/us/app/id%@?ls=1&mt=8", STOREAPPID]]; [[UIApplication sharedApplication] openURL:url]; }]; UIAlertAction *actionNo = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { }]; [alercConteoller addAction:actionYes]; [alercConteoller addAction:actionNo]; [self presentViewController:alercConteoller animated:YES completion:nil]; }else{ NSLog(@"版本號好像比商店大噢!檢測到不須要更新"); } }
4:TCP協議中的三次握手和四次揮手(圖解)ide
注意:左右兩豎線是兩端不一樣的狀態,中間是傳遞字體
三次握手鍊接:url
首先Client端發送鏈接請求報文,Server段接受鏈接後回覆ACK報文,併爲此次鏈接分配資源。Client端接收到ACK報文後也向Server段發生ACK報文,並分配資源,這樣TCP鏈接就創建了。spa
四次握手斷開:插件
假設Client端發起中斷鏈接請求,也就是發送FIN報文。Server端接到FIN報文後,意思是說"我Client端沒有數據要發給你了",可是若是你還有數據沒有發送完成,則沒必要急着關閉Socket,能夠繼續發送數據。因此你先發送ACK,"告訴Client端,你的請求我收到了,可是我還沒準備好,請繼續你等個人消息"。這個時候Client端就進入FIN_WAIT狀態,繼續等待Server端的FIN報文。當Server端肯定數據已發送完成,則向Client端發送FIN報文,"告訴Client端,好了,我這邊數據發完了,準備好關閉鏈接了"。Client端收到FIN報文後,"就知道能夠關閉鏈接了,可是他仍是不相信網絡,怕Server端不知道要關閉,因此發送ACK後進入TIME_WAIT狀態,若是Server端沒有收到ACK則能夠重傳。「,Server端收到ACK後,"就知道能夠斷開鏈接了"。Client端等待了2MSL後依然沒有收到回覆,則證實Server端已正常關閉,那好,我Client端也能夠關閉鏈接了。Ok,TCP鏈接就這樣關閉了!
1.物理層:主要定義物理設備標準,如網線的接口類型、光纖的接口類型、各類傳輸介質的傳輸速率等。它的主要做用是傳輸比特流(就是由一、0轉化爲電流強弱來進行傳輸,到達目的地後在轉化爲一、0,也就是咱們常說的數模轉換與模數轉換)。這一層的數據叫作比特。
2.數據鏈路層:定義瞭如何讓格式化數據以進行傳輸,以及如何讓控制對物理介質的訪問。這一層一般還提供錯誤檢測和糾正,以確保數據的可靠傳輸。
3.網絡層:在位於不一樣地理位置的網絡中的兩個主機系統之間提供鏈接和路徑選擇。Internet的發展使得從世界各站點訪問信息的用戶數大大增長,而網絡層正是管理這種鏈接的層。
4.傳輸層:定義了一些傳輸數據的協議和端口號(WWW端口80等),如:TCP(傳輸控制協議,傳輸效率低,可靠性強,用於傳輸可靠性要求高,數據量大的數據),UDP(用戶數據報協議,與TCP特性偏偏相反,用於傳輸可靠性要求不高,數據量小的數據,如QQ聊天數據就是經過這種方式傳輸的)。 主要是將從下層接收的數據進行分段和傳輸,到達目的地址後再進行重組。經常把這一層數據叫作段。
5.會話層:經過傳輸層(端口號:傳輸端口與接收端口)創建數據傳輸的通路。主要在你的系統之間發起會話或者接受會話請求(設備之間須要互相認識能夠是IP也能夠是MAC或者是主機名)
6.表示層:可確保一個系統的應用層所發送的信息能夠被另外一個系統的應用層讀取。例如,PC程序與另外一臺計算機進行通訊,其中一臺計算機使用擴展二一十進制交換碼(EBCDIC),而另外一臺則使用美國信息交換標準碼(ASCII)來表示相同的字符。若有必要,表示層會經過使用一種通格式來實現多種數據格式之間的轉換。
7.應用層: 是最靠近用戶的OSI層。這一層爲用戶的應用程序(例如電子郵件、文件傳輸和終端仿真)提供網絡服務。
5:關於QBImagePickerController選擇單張
- (void)qb_imagePickerController:(QBImagePickerController *)imagePickerController didSelectAsset:(ALAsset *)asset{ NSMutableArray *selectedAssetURLs = [NSMutableArray new]; NSMutableArray *projectBLSImageInfo = [NSMutableArray new]; NSURL *assetURL = [asset valueForProperty:ALAssetPropertyAssetURL]; [selectedAssetURLs addObject:assetURL]; BLSImageInfo *tweetImg = [BLSImageInfo tweetImageWithAssetURL:assetURL]; [projectBLSImageInfo addObject:tweetImg]; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ self.curProjectImage.selectedAssetURLs = selectedAssetURLs; self.curProjectImage.projectImages=projectBLSImageInfo; [self dismissViewControllerAnimated:YES completion:nil]; } - (void)qb_imagePickerControllerDidCancel:(QBImagePickerController *)imagePickerController{ [self dismissViewControllerAnimated:YES completion:nil]; }
單張執行 qb_imagePickerController:(QBImagePickerController *)imagePickerController didSelectAsset:(ALAsset *)asset
若是是多張則是執行:qb_imagePickerController:(QBImagePickerController *)imagePickerController didSelectAssets:(NSArray *)assets
- (void)qb_imagePickerController:(QBImagePickerController *)imagePickerController didSelectAssets:(NSArray *)assets{ NSMutableArray *selectedAssetURLs = [NSMutableArray new]; NSMutableArray *projectBLSImageInfo = [NSMutableArray new]; [imagePickerController.selectedAssetURLs enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { [selectedAssetURLs addObject:obj]; BLSImageInfo *tweetImg = [BLSImageInfo tweetImageWithAssetURL:obj]; [projectBLSImageInfo addObject:tweetImg]; }]; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ self.curProjectImage.selectedAssetURLs = selectedAssetURLs; self.curProjectImage.projectImages=projectBLSImageInfo; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [self.myTableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:0 inSection:1]] withRowAnimation:UITableViewRowAnimationFade]; }); }); [self dismissViewControllerAnimated:YES completion:nil]; } - (void)qb_imagePickerControllerDidCancel:(QBImagePickerController *)imagePickerController{ [self dismissViewControllerAnimated:YES completion:nil]; }
還要結合相應的屬性進行:
QBImagePickerController *imagePickerController = [[QBImagePickerController alloc] init]; [imagePickerController.selectedAssetURLs removeAllObjects]; [imagePickerController.selectedAssetURLs addObjectsFromArray:self.curProjectImage.selectedAssetURLs]; imagePickerController.filterType = QBImagePickerControllerFilterTypePhotos; imagePickerController.delegate = self; imagePickerController.allowsMultipleSelection = YES; UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:imagePickerController]; [self presentViewController:navigationController animated:YES completion:NULL];
6:字符串按多個符號分割
7:判斷當前ViewController是push仍是present的方式顯示的
NSArray *viewcontrollers=self.navigationController.viewControllers; if (viewcontrollers.count > 1) { if ([viewcontrollers objectAtIndex:viewcontrollers.count - 1] == self) { //push方式 [self.navigationController popViewControllerAnimated:YES]; } } else { //present方式 [self dismissViewControllerAnimated:YES completion:nil]; }
8:修改UITextField中Placeholder的文字顏色
[textField setValue:[UIColor redColor] forKeyPath:@"_placeholderLabel.textColor"];
9:iOS 開發中一些相關的路徑
模擬器的位置: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs 文檔安裝位置: /Applications/Xcode.app/Contents/Developer/Documentation/DocSets 插件保存路徑: ~/Library/ApplicationSupport/Developer/Shared/Xcode/Plug-ins 自定義代碼段的保存路徑: ~/Library/Developer/Xcode/UserData/CodeSnippets/ 若是找不到CodeSnippets文件夾,能夠本身新建一個CodeSnippets文件夾。 描述文件路徑 ~/Library/MobileDevice/Provisioning Profiles