nsstring

iOS-UICollectionView快速构造/拖拽重排/轮播实现

▼魔方 西西 提交于 2020-03-06 13:42:26
代码地址如下: http://www.demodashi.com/demo/11366.html 目录 UICollectionView 的定义 UICollectionView 快速构建GridView网格视图 UICollectionView 拖拽重排处理(iOS8.x-/iOS9.x+) UICollectionView 实现简单轮播 UICollectionView的定义 UICollectionView 同 UITableView 一样,是iOS中最常用到数据展示视图。 官方定义: An object that manages an ordered collection of data items and presents them using customizable layouts. 提供管理有序数据集合且可定制布局能力的对象 UICollectionView 显示内容时: 通过 dataSource 获取 cell 通过 UICollectionViewLayout 获取 layout attributes 布局属性 通过对应的 layout attributes 对 cell 进行调整,完成布局 UICollectionView 交互则是通过丰富的 delegate 方法实现 iOS10中增加了一个新的预处理protocol

iOS-通过日期计算是周几

你离开我真会死。 提交于 2020-03-06 13:00:36
//通过日期求星期 - (NSString*)fromDateToWeek:(NSString*)selectDate { NSInteger yearInt = [selectDate substringWithRange:NSMakeRange(0, 4)].integerValue; NSInteger monthInt = [selectDate substringWithRange:NSMakeRange(4, 2)].integerValue; NSInteger dayInt = [selectDate substringWithRange:NSMakeRange(6, 2)].integerValue; int c = 20;//世纪 NSInteger y = yearInt -1;//年 NSInteger d = dayInt; NSInteger m = monthInt; int w =(y+(y/4)+(c/4)-2*c+(26*(m+1)/10)+d-1)%7; NSString *weekDay = @"" ; switch (w) { case 0: weekDay = @"周日"; break; case 1: weekDay = @"周一"; break; case 2: weekDay = @"周二"; break; case 3:

iOS开发之AFNetworking 3.0.4使用

一个人想着一个人 提交于 2020-03-06 10:58:08
博客迁移到简书一来,一直没有时间来写博客了,以前的也没有整理,这个算是简书上的第一个博客吧!以后有时间还是得把以前的迁移过来,毕竟都是心血啊,也有转载的很多大神们的技术文章,舍不得丢弃呀。。。 昨天使用Cocoapods导入AFN做POST的时候,导入的最新版的3.0.4,突然发现找不到AFHTTPRequestOperationManager了。。。上github上一看,发现没有这个了。刚开始以为是cocoapods没有给我导进去,因为是小demo,就想自己写一个网络请求的,发现也没有这NSURLConnection了,被弃用了,突然意识到,这个就是AFHTTPRequestOperationManager找不到的原因了,它是基于NSURLConnection封装的!!于是找了一下,现在都用的是NSURLSession了,AFN中用的是AFHTTPSessionManager了~~ 特地记录下来,以便遇到这个的朋友们看看! ps:如果想用以前的话,cocoapods 就不要用最新的版本了,2.6的上面有。 GET请求 AFHTTPSessionManager *manager = [AFHTTPSessionManager manager]; [manager GET:URL parameters:nil progress:^(NSProgress * _Nonnull

(绝对有用)iOS获取UUID,并使用keychain存储

て烟熏妆下的殇ゞ 提交于 2020-03-06 10:42:35
UDID被弃用,使用UUID来作为设备的唯一标识。获取到UUID后,如果用NSUserDefaults存储,当程序被卸载后重装时,再获得的UUID和之前就不同了。使用keychain存储可以保证程序卸载重装时,UUID不变。但当刷机或者升级系统后,UUID还是会改变的。但这仍是目前为止最佳的解决办法了,如果有更好的解决办法,欢迎留言。 (我整理的解决办法的参考来源: http://blog.k-res.net/archives/1081.html) 给大家两个类: UUID.h中的代码: #import 尖括号(Foundation/Foundation.h) @interface UUID : NSObject +(NSString *)getUUID; @end UUID.m中的代码: #import "UUID.h" #import 尖括号(Foundation/Foundation.h) #import "KeychainItemWrapper.h" @implementation UUID +(NSString *)getUUID { KeychainItemWrapper *keychainItem = [[KeychainItemWrapper alloc] initWithIdentifier:@"UUID" accessGroup:@"YOUR_BUNDLE

Objective-C之NSString和NSMutableString

三世轮回 提交于 2020-03-05 09:30:19
Objective-C 中核心处理字符串的类是 NSString 与 NSMutableString ,这两个类最大的区别就是NSString 创建赋值以后该字符串的内容与长度不能在动态的更改,除非重新给这个字符串赋值。而NSMutableString 创建赋值以后可以动态在该字符串上更改内容与长度。 +(id) stringWithContentsOfFile:path encoding:enc error:err 创建一个新字符串并将其设置为path指定的文件的内容,使用字符编码enc,如果非零,则返回err中错误 +(id) stringWithContentsOfURL:url encoding:enc error:err 创建一个新的字符串,并将其设置为url的内容,使用字符编码enc,如果非零,则返回err中的错误 +(id) string 创建一个新的空字符串 +(id) stringWithString:nsstring 创建一个新的字符串,并将其设置为nsstring NSString *str = @"1"; //initwithstring和stringwithtstring是不是现在不可以直接加字符串,而是必须加字符串的名字? NSString *str2 = [NSString stringWithString:str]; -(id

iOS UI控件详解—「UICollectionView综合视图」

烂漫一生 提交于 2020-03-04 11:04:17
Write in the first【写在最前】 UITableView 熟悉吧, UICollectionView 必须熟悉吧。 在 WWDC2012 中的 Introducing Collection Views ,苹果首次介绍了 UICollectionView ,类似 UITableView 的用法使人很容易接受,但强大的自定义布局,又使其相较于 UITableView 有了选择它的更多理由, UITableView 中的表格只支持单排列表,没有办法支持网格列表模式, CollectionView 有着灵活的布局特性,这一点充分说明我们在学会 UITableView 的基础上,再去学习推敲 CollectionView 的必要性。 本篇文章主要从【 UICollectionView 系统文件注解】学习总结。 在「时间 & 知识 」有限内,总结的文章难免有「未全、不足 」的地方,还望各位好友指出,以提高文章质量。 目录: UICollectionView概念 UICollectionView基本组成 UICollectionView层次结构 1.UICollectionView 继承于 UIScrollView 2.UICollectionViewDataSource数据源 3.UICollectionViewDelegate代理 4

Object-C 中各数据类型转换 NSData转NSString,Byte,UIImage

浪子不回头ぞ 提交于 2020-03-04 07:26:02
1,NSData 与 NSString    NSData --> NSString    NSString *aString = [[NSString alloc] initWithData:adata encoding:NSUTF8StringEncoding];    NSString --> NSData    NSString *aString = @"1234";   NSData *aData = [aString dataUsingEncoding: NSUTF8StringEncoding]; 2,NSData 与 Byte    NSData --> Byte    NSString *testString = @"1234567890";   NSData *testData = [testString dataUsingEncoding: NSUTF8StringEncoding];   Byte *testByte = (Byte *)[testData bytes];    Byte --> NSData    Byte byte[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23};   NSData *adata = [[NSData alloc]

蓝牙功能

偶尔善良 提交于 2020-03-03 15:29:54
蓝牙功能 作为蓝牙中心,连接外设 一般性的步骤是先扫描设备,然后根据蓝牙设备的名称等信息找到需要连接的设备,进行连接 然后获取设备的服务,可以订阅对应的服务,可以对设备进行写入 // // ViewController.m // BlueTooth // // Created by JackXu on 15/6/9. // Copyright (c) 2015年 BFMobile. All rights reserved. // #import "ViewController.h" #define MyDeviceName @"HMSoft" @interface ViewController () @property (nonatomic, strong) CBCentralManager *centralMgr; @property (nonatomic, strong) CBPeripheral *discoveredPeripheral; @property (nonatomic, strong) CBCharacteristic *writeCharacteristic; @property (nonatomic,strong) CBCharacteristic *testCharacteristic; @property (weak, nonatomic)

iOS中日期和字符串的相互转化

梦想与她 提交于 2020-03-02 12:41:29
例1、 从服务器段获取到的字符串转化为时间如: //网络请求获取的数据 NSString *time = @"495946429"; NSInteger num = [time integerValue]; NSDateFormatter *formatter = [[NSDateFormatter alloc]init]; [formatter setDateStyle:NSDateFormatterMediumStyle]; [formatter setTimeStyle:NSDateFormatterShortStyle]; [formatter setDateFormat:@"YYYY-MM-dd"]; NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:num]; NSString *confromTimespStr = [formatter stringFromDate:confromTimesp]; NSLog(@"%@",confromTimespStr); 转化之后结果为: 1985-09-19 例2、如何如何将一个字符串如“ 20110826134106”装化为任意的日期时间格式,下面列举两种类型: NSString *string = @"20110826134106";

Objective-C的self.用法

倖福魔咒の 提交于 2020-03-02 03:54:49
转自: http://mobile.51cto.com/iphone-313096.htm 进入正题, 我们经常会在官方文档里看到这样的代码: MyClass.h @interface MyClass : NSObject { MyObject *myObject; } @property (nonatomic, retain) MyObject *myObject; @end MyClass.m @synthesize myObject; -(id)init{ if (self = [super init]){ MyObject * aMyObject = [[MyObject alloc] init]; self.myObject = aMyObject; [aMyObject release]; } return self; } 创建一个Student类,继承NSObject类,代码: #import <Foundation/Foundation.h> @interface Student : NSObject{ NSString *idd; NSString *name; } @property (nonatomic, retain) NSString *idd; @property (nonatomic, retain) NSString *name; @end .m文件