添加了加载网络图片的类

This commit is contained in:
fengshuo
2021-09-17 11:10:17 +08:00
committed by zu
parent 2c6b42a6f0
commit fbf42959fb
7 changed files with 273 additions and 1 deletions

View File

@@ -15,6 +15,8 @@ target 'xplan-ios' do
pod 'NTESQuickPass', '~> 2.1.6'
#模型转化
pod 'MJExtension'
#图片加载
pod 'SDWebImage'
#登录的
pod 'mob_sharesdk'
pod 'mob_sharesdk/ShareSDKPlatforms/QQ'

View File

@@ -34,6 +34,9 @@ PODS:
- MOBFoundation (3.2.27)
- NTESQuickPass (2.1.9)
- ReactiveObjC (3.1.1)
- SDWebImage (5.11.1):
- SDWebImage/Core (= 5.11.1)
- SDWebImage/Core (5.11.1)
- YYText (1.0.7)
DEPENDENCIES:
@@ -47,6 +50,7 @@ DEPENDENCIES:
- mob_sharesdk/ShareSDKPlatforms/WeChat
- NTESQuickPass (~> 2.1.6)
- ReactiveObjC
- SDWebImage
- YYText
SPEC REPOS:
@@ -59,6 +63,7 @@ SPEC REPOS:
- MOBFoundation
- NTESQuickPass
- ReactiveObjC
- SDWebImage
- YYText
SPEC CHECKSUMS:
@@ -70,8 +75,9 @@ SPEC CHECKSUMS:
MOBFoundation: efdc3ce6b843fbc10ae8c1c6122a02b0d845b39b
NTESQuickPass: 8431dc52737c95883cd382c2ee75664d58f39377
ReactiveObjC: 011caa393aa0383245f2dcf9bf02e86b80b36040
SDWebImage: a7f831e1a65eb5e285e3fb046a23fcfbf08e696d
YYText: 5c461d709e24d55a182d1441c41dc639a18a4849
PODFILE CHECKSUM: 82677bb54bd8940f2a6cc6f00b6eaefb58c721b7
PODFILE CHECKSUM: 687d511184d9d6e28c8efe12fb40a25936953ff4
COCOAPODS: 1.10.1

View File

@@ -85,6 +85,8 @@
E872308926E89BE000B90D4F /* LoginPhoneViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E872308826E89BE000B90D4F /* LoginPhoneViewController.m */; };
E872308D26E89DAA00B90D4F /* LoginInputView.m in Sources */ = {isa = PBXBuildFile; fileRef = E872308C26E89DAA00B90D4F /* LoginInputView.m */; };
E872309326E8D31500B90D4F /* LoginVerifCodeView.m in Sources */ = {isa = PBXBuildFile; fileRef = E872309226E8D31500B90D4F /* LoginVerifCodeView.m */; };
E8AC720D26F435F5007D6E91 /* UIImageView+LoadImage.m in Sources */ = {isa = PBXBuildFile; fileRef = E8AC720C26F435F5007D6E91 /* UIImageView+LoadImage.m */; };
E8AC721026F43955007D6E91 /* UIImageViewConstant.m in Sources */ = {isa = PBXBuildFile; fileRef = E8AC720F26F43955007D6E91 /* UIImageViewConstant.m */; };
E8B825B726E9A7D8009E8E9F /* BaseObject.m in Sources */ = {isa = PBXBuildFile; fileRef = E8B825B626E9A7D8009E8E9F /* BaseObject.m */; };
E8B825BF26E9E57D009E8E9F /* LoginTicketInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = E8B825BE26E9E57D009E8E9F /* LoginTicketInfo.m */; };
E8B825C226EA00DF009E8E9F /* LoginVerifCodePresent.m in Sources */ = {isa = PBXBuildFile; fileRef = E8B825C126EA00DF009E8E9F /* LoginVerifCodePresent.m */; };
@@ -259,6 +261,10 @@
E872308C26E89DAA00B90D4F /* LoginInputView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = LoginInputView.m; sourceTree = "<group>"; };
E872309126E8D31500B90D4F /* LoginVerifCodeView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LoginVerifCodeView.h; sourceTree = "<group>"; };
E872309226E8D31500B90D4F /* LoginVerifCodeView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = LoginVerifCodeView.m; sourceTree = "<group>"; };
E8AC720B26F435F5007D6E91 /* UIImageView+LoadImage.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "UIImageView+LoadImage.h"; sourceTree = "<group>"; };
E8AC720C26F435F5007D6E91 /* UIImageView+LoadImage.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "UIImageView+LoadImage.m"; sourceTree = "<group>"; };
E8AC720E26F43955007D6E91 /* UIImageViewConstant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = UIImageViewConstant.h; sourceTree = "<group>"; };
E8AC720F26F43955007D6E91 /* UIImageViewConstant.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = UIImageViewConstant.m; sourceTree = "<group>"; };
E8B825B526E9A7D8009E8E9F /* BaseObject.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BaseObject.h; sourceTree = "<group>"; };
E8B825B626E9A7D8009E8E9F /* BaseObject.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BaseObject.m; sourceTree = "<group>"; };
E8B825BD26E9E57D009E8E9F /* LoginTicketInfo.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LoginTicketInfo.h; sourceTree = "<group>"; };
@@ -464,6 +470,7 @@
189DD56C26DF5B5400AB55B1 /* UI */ = {
isa = PBXGroup;
children = (
E8AC720A26F435AF007D6E91 /* UIImageView */,
E81366F926F0D27A0076364C /* UIButton */,
189DD54926DE338800AB55B1 /* BaseViewController.h */,
189DD54A26DE338800AB55B1 /* BaseViewController.m */,
@@ -752,6 +759,17 @@
path = CustomView;
sourceTree = "<group>";
};
E8AC720A26F435AF007D6E91 /* UIImageView */ = {
isa = PBXGroup;
children = (
E8AC720B26F435F5007D6E91 /* UIImageView+LoadImage.h */,
E8AC720C26F435F5007D6E91 /* UIImageView+LoadImage.m */,
E8AC720E26F43955007D6E91 /* UIImageViewConstant.h */,
E8AC720F26F43955007D6E91 /* UIImageViewConstant.m */,
);
path = UIImageView;
sourceTree = "<group>";
};
E8B825BC26E9E520009E8E9F /* Model */ = {
isa = PBXGroup;
children = (
@@ -1009,6 +1027,7 @@
189DD54B26DE338800AB55B1 /* BaseViewController.m in Sources */,
E8E70D8626F2F55C00F03460 /* XPMineAccountView.m in Sources */,
E81C279026EB314D0031E639 /* LoginForgetEditView.m in Sources */,
E8AC721026F43955007D6E91 /* UIImageViewConstant.m in Sources */,
E81C27A026EEF83D0031E639 /* XPHtmlUrl.m in Sources */,
18E7B1B726E8B2D10064BC9B /* Api+Main.m in Sources */,
E8B825C226EA00DF009E8E9F /* LoginVerifCodePresent.m in Sources */,
@@ -1018,6 +1037,7 @@
18E7B31E26F0984C0064BC9B /* UserLevelVo.m in Sources */,
18E7B31B26F0982E0064BC9B /* UserExpand.m in Sources */,
E8B825CD26EA18C8009E8E9F /* ThemeColor.m in Sources */,
E8AC720D26F435F5007D6E91 /* UIImageView+LoadImage.m in Sources */,
E8CEA03D26EA3DE500644B44 /* LoginPasswordPresent.m in Sources */,
E8E70D7726F2F15100F03460 /* XPMineViewController.m in Sources */,
189DD52E26DE255300AB55B1 /* AppDelegate.m in Sources */,

View File

@@ -0,0 +1,53 @@
//
// UIImageView+LoadImage.h
// xplan-ios
//
// Created by 冯硕 on 2021/9/17.
// 加载图片的类
#import <UIKit/UIKit.h>
#import "UIImageViewConstant.h"
NS_ASSUME_NONNULL_BEGIN
@interface UIImageView (LoadImage)
/// 加载图片
/// @param url 图片的链接地址
/// @param placeholderImage 站位图
/// @param type 类型 用于设置大小
/// @param cornerRadious 弧度
/// @param success 成功的回调
- (void)load_setImageImageWithUrl:(NSString *)url
placeholderImage:(NSString *)placeholderImage
type:(ImageType)type
cornerRadious:(CGFloat)cornerRadious
success:(void (^)(UIImage *image))success;
/// 加载图片不需要成功的回调
/// @param url 图片的链接地址
/// @param placeholderImage 站位图
/// @param type 类型 用于设置大小
/// @param cornerRadious 弧度
- (void)load_setImageImageWithUrl:(NSString *)url
placeholderImage:(NSString *)placeholderImage
type:(ImageType)type
cornerRadious:(CGFloat)cornerRadious;
/// 加载图片 没有圆角的设置
/// @param url 图片的链接地址
/// @param placeholderImage 站位图
/// @param type 类型 用于设置大小
- (void)load_setImageImageWithUrl:(NSString *)url placeholderImage:(NSString *)placeholderImage type:(ImageType)type;
/// 加载图片 没有类型的设置
/// @param url 图片的链接地址
/// @param placeholderImage 站位图
- (void)load_setImageImageWithUrl:(NSString *)url placeholderImage:(NSString *)placeholderImage;
/// 加载图片 回调图片的
/// @param url 图片的链接地址
/// @param placeholderImage 站位图
/// @param success 成功了
- (void)load_setImageImageWithUrl:(NSString *)url placeholderImage:(NSString *)placeholderImage success:(void (^)(UIImage *image))success;
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,140 @@
//
// UIImageView+LoadImage.m
// xplan-ios
//
// Created by on 2021/9/17.
//
#import "UIImageView+LoadImage.h"
#import <UIImageView+WebCache.h>
@implementation UIImageView (LoadImage)
///
/// @param url
/// @param placeholderImage
/// @param type
/// @param cornerRadious
/// @param success
- (void)load_setImageImageWithUrl:(NSString *)url
placeholderImage:(NSString *)placeholderImage
type:(ImageType)type
cornerRadious:(CGFloat)cornerRadious
success:(void (^)(UIImage *image))success {
NSMutableString *urlString = [NSMutableString stringWithString:url];
NSString *configUrl = nil;
switch (type) {
case ImageTypeUserIcon:
{
configUrl = kImageTypeUserIcon;
}
break;
case ImageTypeCornerAvatar:
{
configUrl = kImageTypeCornerAvatar;
}
break;
case ImageTypeRoomFace:
{
configUrl = kImageTypeRoomFace;
}
break;
case ImageTypeUserLibaryDetail:
{
configUrl = kImageTypeUserLibaryDetail;
}
break;
case ImageTypeRoomGift:
{
configUrl = kImageTypeRoomGift;
}
break;
default:
break;
}
if (configUrl) {
if ([url containsString:@"?"]) {
[urlString appendString:@"|"];
}else{
[urlString appendString:@"?"];
}
[urlString appendString:configUrl];
}
if (cornerRadious > 0) {
[urlString appendString:[NSString stringWithFormat:@"|roundPic/radius/%f",cornerRadious]];
}
NSString *encodeStr = [self URLEncodedString:urlString];
if (placeholderImage.length > 0) {
[self sd_setImageWithURL:[NSURL URLWithString:encodeStr] placeholderImage:[UIImage imageNamed:placeholderImage] options:SDWebImageRetryFailed completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
if (success) {
success(image);
}
}];
}else{
[self sd_setImageWithURL:[NSURL URLWithString:encodeStr] placeholderImage:nil options:SDWebImageRetryFailed completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
if (success) {
success(image);
}
}];
}
}
///
/// @param url
/// @param placeholderImage
/// @param type
/// @param cornerRadious
- (void)load_setImageImageWithUrl:(NSString *)url
placeholderImage:(NSString *)placeholderImage
type:(ImageType)type
cornerRadious:(CGFloat)cornerRadious {
[self load_setImageImageWithUrl:url placeholderImage:placeholderImage type:type cornerRadious:cornerRadious success:nil];
}
///
/// @param url
/// @param placeholderImage
/// @param type
- (void)load_setImageImageWithUrl:(NSString *)url placeholderImage:(NSString *)placeholderImage type:(ImageType)type{
[self load_setImageImageWithUrl:url placeholderImage:placeholderImage type:type cornerRadious:0];
}
///
/// @param url
/// @param placeholderImage
- (void)load_setImageImageWithUrl:(NSString *)url placeholderImage:(NSString *)placeholderImage {
[self load_setImageImageWithUrl:url placeholderImage:placeholderImage type:0 cornerRadious:0];
}
///
/// @param url
/// @param placeholderImage
/// @param success
- (void)load_setImageImageWithUrl:(NSString *)url placeholderImage:(NSString *)placeholderImage success:(void (^)(UIImage *image))success{
[self sd_setImageWithURL:[NSURL URLWithString:url] placeholderImage:placeholderImage ? [UIImage imageNamed:placeholderImage] : nil completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
success(image);
}];
}
- (NSString *)URLEncodedString:(NSString *)string
{
NSString *encodedString = (NSString *)
CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,
(CFStringRef)string,
NULL,
(CFStringRef)@"|",
kCFStringEncodingUTF8));
return encodedString;
}
@end

View File

@@ -0,0 +1,32 @@
//
// UIImageViewConstant.h
// xplan-ios
//
// Created by 冯硕 on 2021/9/17.
// 存放一些 加载图片 需要做的裁剪的key
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface UIImageViewConstant : NSObject
UIKIT_EXTERN NSString * const kImageTypeRoomFace; //房间表情
UIKIT_EXTERN NSString * const kImageTypeRoomGift; //房间礼物
UIKIT_EXTERN NSString * const kImageTypeUserIcon; //用户头像60x60
UIKIT_EXTERN NSString * const kImageTypeUserLibaryDetail;//用户相册大图nil
UIKIT_EXTERN NSString * const kImageTypeCornerAvatar;//圆角图形会先把图形裁剪成正方形并且转换为png
#pragma mark - 图片相关的
typedef NS_ENUM(NSUInteger,ImageType){
ImageTypeRoomFace, //房间表情
ImageTypeRoomGift, //房间礼物
ImageTypeUserIcon, //用户头像60x60
ImageTypeUserLibaryDetail, //用户相册大图
ImageTypeCornerAvatar, //圆角图形会先把图形裁剪成正方形并且转换为png
};
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,19 @@
//
// UIImageViewConstant.m
// xplan-ios
//
// Created by on 2021/9/17.
//
#import "UIImageViewConstant.h"
@implementation UIImageViewConstant
NSString * const kImageTypeRoomFace = @""; //
NSString * const kImageTypeRoomGift = @""; //
NSString * const kImageTypeUserIcon = @"imageMogr2/auto-orient/thumbnail/150x150"; //150x150
NSString * const kImageTypeUserLibaryDetail = @""; //nil
NSString * const kImageTypeCornerAvatar = @"imageMogr2/auto-orient/thumbnail/300x300/format/png";
@end