Reachability 相信很多人都会用的到网络监测吧,这个是很多人都在用的一个类,很方便,它有三个定义类型
typedef enum {
NotReachable = 0,//无网络
ReachableViaWiFi,//移动网络
ReachableViaWWAN//WIFI状态
} NetworkStatus;
根据这个就可以判断了
Masonry 纯代码适配,是一个很好用的第三方,目前很多人都在用,但是有一个缺点是代码量比较大,对于要快速开发 或者 项目比较急得人来说可能相对来说有点不合适,我就不详细介绍他的用法了
关于代码适配,我在这重点介绍一下SDAutoLayout这个第三方适配,它相对于Masonry更简洁,速度快,一句代码完成适配 怎么样?是不是很牛的样子啊好了,现在说一下用法
pod 'SDAutoLayout', '~> 2.1.7' 先导入项目https://github.com/gsdios/SDAutoLayout
☆☆SDAutoLayout 基础版视频教程:http://www.letv.com/ptv/vplay/24038772.html ☆☆
☆☆ SDAutoLayout 进阶版视频教程:http://www.letv.com/ptv/vplay/24381390.html ☆☆
☆☆ SDAutoLayout 原理简介视频教程:http://www.iqiyi.com/w_19rt0tec4p.html ☆☆
☆☆SDAutoLayout 朋友圈demo视频教程:http://v.youku.com/v_show/id_XMTYzNzg2NzA0MA==.html ☆☆
微信demo完整版地址:https://github.com/gsdios/GSD_WeiXin
下面粘一段适配代码
_img = [[UIImageView alloc] init];
[self addSubview:_img];
_img.sd_layout.leftSpaceToView(self,5).topSpaceToView(self,5).widthIs(80).heightIs(80);
_productName = [[UILabel alloc] init];
_productName.numberOfLines = 0;
_productName.font = [UIFont systemFontOfSize:15.0];
[self addSubview:_productName];
_productName.sd_layout.leftSpaceToView(_img,5).topSpaceToView(self,5).widthIs(SCREEN_WIDTH - 95).heightIs(50);
_priceLab = [[UILabel alloc] init];
_priceLab.textColor = UIRED;
[self addSubview:_priceLab];
_priceLab.sd_layout.leftSpaceToView(_img,5).topSpaceToView(_productName,0).widthIs(SCREEN_WIDTH - 95).heightIs(30);
_orderNum = [[UILabel alloc] init];
_orderNum.font = [UIFont systemFontOfSize:13.0];
[self addSubview:_orderNum];
_orderNum.sd_layout.leftSpaceToView(self,5).topSpaceToView(_img,0).widthIs(SCREEN_WIDTH / 2 - 5).heightIs(20);
_numPrice = [[UILabel alloc] init];
_numPrice.textAlignment = NSTextAlignmentRight;
_numPrice.textColor = UIRED;
_numPrice.font = [UIFont systemFontOfSize:15.0f];
[self addSubview:_numPrice];
_numPrice.sd_layout.leftSpaceToView(_orderNum,5).topSpaceToView(_priceLab,0).widthIs(SCREEN_WIDTH / 2 - 10).heightIs(20);
每个控件的最后一句就是适配代码,够简洁吧? 它还可以自适应cell高度哦!
选择图片的第三方库ZYQAssetPickerController,大家在开发中会遇到多选图片上传的功能,用这个就行,不过有点老了,谁有最新的欢迎提供!!!
使用也是很简单的 首先要导入项目pod 'ZYQAssetPickerController', '~> 1.0.0'
然后把#import "ZYQAssetPickerController.h" 导入需要的类里面
开代理ZYQAssetPickerControllerDelegate
// 获得所有的自定义相簿
PHFetchResult<PHAssetCollection *> *assetCollections = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeAlbum subtype:PHAssetCollectionSubtypeAlbumRegular options:nil];
// 遍历所有的自定义相簿
for (PHAssetCollection *assetCollection in assetCollections) {
[self enumerateAssetsInAssetCollection:assetCollection original:YES];
}
// 获得相机胶卷
PHAssetCollection *cameraRoll = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeSmartAlbum subtype:PHAssetCollectionSubtypeSmartAlbumUserLibrary options:nil].lastObject;
// 遍历相机胶卷,获取大图
[self enumerateAssetsInAssetCollection:cameraRoll original:YES];
picker.delegate = self;
[self presentViewController:picker animated:YES completion:nil];
上面是点击方法
- (void)getThumbnailImages
{
// 获得所有的自定义相簿
PHFetchResult<PHAssetCollection *> *assetCollections = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeAlbum subtype:PHAssetCollectionSubtypeAlbumRegular options:nil];
// 遍历所有的自定义相簿
for (PHAssetCollection *assetCollection in assetCollections) {
[self enumerateAssetsInAssetCollection:assetCollection original:NO];
}
// 获得相机胶卷
PHAssetCollection *cameraRoll = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeSmartAlbum subtype:PHAssetCollectionSubtypeSmartAlbumUserLibrary options:nil].lastObject;
[self enumerateAssetsInAssetCollection:cameraRoll original:NO];
}
- (void)enumerateAssetsInAssetCollection:(PHAssetCollection *)assetCollection original:(BOOL)original
{
// NSLog(@"相簿名:%@", assetCollection.localizedTitle);
[imgArr removeAllObjects];
PHImageRequestOptions *options = [[PHImageRequestOptions alloc] init];
// 同步获得图片, 只会返回1张图片
options.synchronous = YES;
// 获得某个相簿中的所有PHAsset对象
PHFetchResult<PHAsset *> *assets = [PHAsset fetchAssetsInAssetCollection:assetCollection options:nil];
for (PHAsset *asset in assets) {
// 是否要原图
CGSize size = original ? CGSizeMake(asset.pixelWidth, asset.pixelHeight) : CGSizeZero;
// 从asset中获得图片
[[PHImageManager defaultManager] requestImageForAsset:asset targetSize:size contentMode:PHImageContentModeDefault options:options resultHandler:^(UIImage * _Nullable result, NSDictionary * _Nullable info) {
NSLog(@"%@", result);
}];
}
}
最终我们要得到图片
/*
得到选中的图片
*/
pragma mark - ZYQAssetPickerController Delegate
-(void)assetPickerController:(ZYQAssetPickerController *)picker didSelectAsset:(ALAsset*)asset
{
picker.maximumNumberOfSelection = 4 - [self.photos count];
}
-(void)assetPickerController:(ZYQAssetPickerController *)picker didFinishPickingAssets:(NSArray *)assets{
[imgArr removeAllObjects];
[picker dismissViewControllerAnimated:YES completion:nil];
for (int i=0; i<assets.count; i++) {
ALAsset *asset=assets[i];
UIImage *tempImg=[UIImage imageWithCGImage:asset.defaultRepresentation.fullScreenImage];
[imgArr addObject:tempImg];
}
[self creatBtn];
///Users/shangce/Desktop/DragonPoints 2/DragonPoints/JudgeViewController.m:269:58: 'defaultRepresentation' is deprecated: first deprecated in iOS 9.0 - Use PHImageRequestOptions with the PHImageManager from the Photos framework instead
}
SDWebImage 这个应该是使用最广泛的了,自动处理图片
没时间整理了 向大家推荐一个博客:http://www.cnblogs.com/oc-bowen/p/5590825.html