IOS开发基础知识--碎片50
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的类扩展:
// 创建水平排列图标 arr中放置了2个或连个以上的初始化后的控件
// alongAxis 轴线方向 固定间隔 头部间隔 尾部间隔
[arr mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedSpacing: leadSpacing: tailSpacing:];
[arr makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(@);
make.height.equalTo(@);
}];
实例:
NSMutableArray *mutableArr = [[NSMutableArray alloc] initWithCapacity:];
for (int i=; i<; 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 = ;
[self addSubview:button];
[mutableArr addObject:button];
} [mutableArr mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedSpacing: leadSpacing: tailSpacing:];
[mutableArr mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(@);
make.height.equalTo(@);
}];
2:YYLabel的简单使用
NSString *title = @"不得不说 YYKit第三方框架确实很牛,YYLabel在富文本显示和操作方面相当强大,尤其是其异步渲染,让界面要多流畅有多流畅,这里我们介绍下简单的使用"; //YYLabel 富文本
YYLabel *titleLabel = [YYLabel new]; //异步渲染 当一个label显示巨量文字的时候就能明显感觉到此功能的强大
titleLabel.displaysAsynchronously = YES;
[self.view addSubView:titleLabel]; titleLable.numOfLines = ;
YYTextContainer *titleContarer = [YYTextContainer new]; //限制宽度
detailContarer.size = CGSizeMake(,CGFLOAT_MAX);
NSMutableAttributedString *titleAttr = [self getAttr:title];
YYTextLayout *titleLayout = [YYTextLayout layoutWithContainer:titleContarer text:titleAttr]; CGFloat titleLabelHeight = titleLayout.textBoundingSize.height;
titleLabel.frame = CGRectMake(,,,titleLabelHeight);
- (NSMutableAttributedString*)getAttr:(NSString*)attributedString {
NSMutableAttributedString * resultAttr = [[NSMutableAttributedString alloc] initWithString:attributedString]; //对齐方式 这里是 两边对齐
resultAttr.yy_alignment = NSTextAlignmentJustified;
//设置行间距
resultAttr.yy_lineSpacing = ;
//设置字体大小
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版本号检测及更新实例
//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 < ) {
NSLog(@"此APPID为未上架的APP或者查询不到");
return;
} NSDictionary *dic = array[];
NSString *appStoreVersion = dic[@"version"];
//打印版本号
NSLog(@"当前版本号:%@\n商店版本号:%@",currentVersion,appStoreVersion);
//设置版本号
currentVersion = [currentVersion stringByReplacingOccurrencesOfString:@"." withString:@""];
if (currentVersion.length==) {
currentVersion = [currentVersion stringByAppendingString:@""];
}else if (currentVersion.length==){
currentVersion = [currentVersion stringByAppendingString:@""];
}
appStoreVersion = [appStoreVersion stringByReplacingOccurrencesOfString:@"." withString:@""];
if (appStoreVersion.length==) {
appStoreVersion = [appStoreVersion stringByAppendingString:@""];
}else if (appStoreVersion.length==){
appStoreVersion = [appStoreVersion stringByAppendingString:@""];
} //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协议中的三次握手和四次挥手(图解)
注意:左右两竖线是两端不同的状态,中间是传递
三次握手连接:
首先Client端发送连接请求报文,Server段接受连接后回复ACK报文,并为这次连接分配资源。Client端接收到ACK报文后也向Server段发生ACK报文,并分配资源,这样TCP连接就建立了。
四次握手断开:
假设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.物理层:主要定义物理设备标准,如网线的接口类型、光纤的接口类型、各种传输介质的传输速率等。它的主要作用是传输比特流(就是由1、0转化为电流强弱来进行传输,到达目的地后在转化为1、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, ), ^{
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, ), ^{
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: inSection:]] 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 > )
{
if ([viewcontrollers objectAtIndex:viewcontrollers.count - ] == 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
IOS开发基础知识--碎片50的更多相关文章
- IOS开发基础知识碎片-导航
1:IOS开发基础知识--碎片1 a:NSString与NSInteger的互换 b:Objective-c中集合里面不能存放基础类型,比如int string float等,只能把它们转化成对象才可 ...
- IOS开发基础知识--碎片33
1:AFNetworking状态栏网络请求效果 直接在AppDelegate里面didFinishLaunchingWithOptions进行设置 [[AFNetworkActivityIndicat ...
- IOS开发基础知识--碎片42
1:报thread 1:exc_bad_access(code=1,address=0x70********) 闪退 这种错误通常是内存管理的问题,一般是访问了已经释放的对象导致的,可以开启僵尸对象( ...
- IOS开发基础知识--碎片3
十二:判断设备 //设备名称 return [UIDevice currentDevice].name; //设备型号,只可得到是何设备,无法得到是第几代设备 return [UIDevice cur ...
- IOS开发基础知识--碎片11
1:AFNetwork判断网络状态 #import “AFNetworkActivityIndicatorManager.h" - (BOOL)application:(UIApplicat ...
- IOS开发基础知识--碎片14
1:ZIP文件压缩跟解压,使用ZipArchive 创建/添加一个zip包 ZipArchive* zipFile = [[ZipArchive alloc] init]; //次数得zipfilen ...
- IOS开发基础知识--碎片16
1:Objective-C语法之动态类型(isKindOfClass, isMemberOfClass,id) 对象在运行时获取其类型的能力称为内省.内省可以有多种方法实现. 判断对象类型 -(BOO ...
- IOS开发基础知识--碎片19
1:键盘事件顺序 UIKeyboardWillShowNotification // 键盘显示之前 UIKeyboardDidShowNotification // 键盘显示完成后 UIKeyboar ...
- IOS开发基础知识--碎片40
1:Masonry快速查看报错小技巧 self.statusLabel = [UILabel new]; [self.contentView addSubview:self.statusLabel]; ...
随机推荐
- [异常特工]android常见bug跟踪
前言 对app的线上bug的收集(友盟.云捕等)有时会得到这样的异常堆栈信息:没有一行代码是有关自身程序代码的.这使得对bug的解决无从下手,根据经验,内存不足OOM,Dialog关闭,ListVie ...
- 【腾讯Bugly干货分享】微信终端跨平台组件 Mars 系列 - 我们如约而至
导语 昨天上午,微信在广州举办了微信公开课Pro.于是,精神哥这两天的朋友圈被小龙的"八不做"刷屏了.小伙伴们可能不知道,下午,微信公开课专门开设了技术分论坛.在分论坛中,微信开源 ...
- ENode 2.8 最新架构图简介
ENode架构图 什么是ENode ENode是一个.NET平台下,纯C#开发的,基于DDD,CQRS,ES,EDA,In-Memory架构风格的,可以帮助开发者开发高并发.高吞吐.可伸缩.可扩展的应 ...
- Fedora 22中的RPM软件包管理工具
Introduction The RPM Package Manager (RPM) is an open packaging system that runs on Fedora as well a ...
- 2000条你应知的WPF小姿势 基础篇<57-62 依赖属性进阶>
在正文开始之前需要介绍一个人:Sean Sexton. 来自明尼苏达双城的软件工程师.最为出色的是他维护了两个博客:2,000ThingsYou Should Know About C# 和 2,00 ...
- 再次学习 java 类的编译
做JAVA开发的都知道myeclipse, 我们在myeclipse中新建一个类,然后保存, 如何正常的话,那么在项目指定的目录(也就是项目的output目录)就会生成同名的class文件, 可是,我 ...
- iOS 之项目中遇到的问题总结
昨天去一家公司面试,面试官问了我在项目开发中遇到过哪些问题,是什么引起的,怎样解决的? 当时由于有点小紧张只说出了一两点,现在就来好好总结一下. 问题: 1.两表联动 所谓的两表联动就是有左右两个表格 ...
- 一、Redis基本操作——String(原理篇)
小喵的唠叨话:最近京东图书大减价,小喵手痒了就买了本<Redis设计与实现>[1]来看看.这里权当小喵看书的笔记啦.这一系列的模式,主要是先介绍Redis的实现原理(可能很大一部分会直接照 ...
- 如何处理CSS3属性前缀
今天闲来无聊,重新来说说CSS3前缀的问题.在春节前和@一丝姐姐说起Sass中有关于gradient的mixins.姐姐说: 为什么还要用mixin呢?为什么不使用Autoprefixer?使用Aut ...
- NotePad++中JSLint的使用
1.第一步下载Notepad++ 2.安装JSLint插件 3.运行JSlint 4.前提是你设置了当前语言或者本身文件就是js 5.JSLint的作用主要就是检查你的JS的规则正确性(至少是绝大部分 ...