NetImageView 和 NetImageYYLabel 整理
This commit is contained in:
@@ -142,7 +142,6 @@
|
||||
E84B0E4C27281530008818C6 /* XPRoomMessageAttributeHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = E84B0E4B27281530008818C6 /* XPRoomMessageAttributeHelper.m */; };
|
||||
E865963F27015A9C00846EBD /* XPMineUserTableView.m in Sources */ = {isa = PBXBuildFile; fileRef = E865963E27015A9C00846EBD /* XPMineUserTableView.m */; };
|
||||
E86596432701611A00846EBD /* UIImage+ImageEffects.m in Sources */ = {isa = PBXBuildFile; fileRef = E86596412701611A00846EBD /* UIImage+ImageEffects.m */; };
|
||||
E86596462701612D00846EBD /* UIImageView+Vague.m in Sources */ = {isa = PBXBuildFile; fileRef = E86596452701612D00846EBD /* UIImageView+Vague.m */; };
|
||||
E86596512701A1C000846EBD /* StatisticsService.m in Sources */ = {isa = PBXBuildFile; fileRef = E86596502701A1C000846EBD /* StatisticsService.m */; };
|
||||
E86596542701A55500846EBD /* StatisticsServiceHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = E86596532701A55500846EBD /* StatisticsServiceHelper.m */; };
|
||||
E8680718271967B00024F48F /* MicroView.m in Sources */ = {isa = PBXBuildFile; fileRef = E8680717271967B00024F48F /* MicroView.m */; };
|
||||
@@ -179,7 +178,6 @@
|
||||
E89DA66727006443008483C1 /* RechargeStorage.m in Sources */ = {isa = PBXBuildFile; fileRef = E89DA66627006443008483C1 /* RechargeStorage.m */; };
|
||||
E89DA67227008D59008483C1 /* WalletInfoModel.m in Sources */ = {isa = PBXBuildFile; fileRef = E89DA67127008D59008483C1 /* WalletInfoModel.m */; };
|
||||
E89DA67527009ACD008483C1 /* XPMineRechargeNavView.m in Sources */ = {isa = PBXBuildFile; fileRef = E89DA67427009ACD008483C1 /* XPMineRechargeNavView.m */; };
|
||||
E8AC720D26F435F5007D6E91 /* UIImageView+LoadImage.m in Sources */ = {isa = PBXBuildFile; fileRef = E8AC720C26F435F5007D6E91 /* UIImageView+LoadImage.m */; };
|
||||
E8AC721026F43955007D6E91 /* UIImageConstant.m in Sources */ = {isa = PBXBuildFile; fileRef = E8AC720F26F43955007D6E91 /* UIImageConstant.m */; };
|
||||
E8AC721326F46ADD007D6E91 /* XPMineSettingViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E8AC721226F46ADD007D6E91 /* XPMineSettingViewController.m */; };
|
||||
E8AC721626F46B06007D6E91 /* XPMineSettingTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = E8AC721526F46B06007D6E91 /* XPMineSettingTableViewCell.m */; };
|
||||
@@ -513,8 +511,6 @@
|
||||
E865963E27015A9C00846EBD /* XPMineUserTableView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = XPMineUserTableView.m; sourceTree = "<group>"; };
|
||||
E86596412701611A00846EBD /* UIImage+ImageEffects.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIImage+ImageEffects.m"; sourceTree = "<group>"; };
|
||||
E86596422701611A00846EBD /* UIImage+ImageEffects.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIImage+ImageEffects.h"; sourceTree = "<group>"; };
|
||||
E86596442701612D00846EBD /* UIImageView+Vague.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "UIImageView+Vague.h"; sourceTree = "<group>"; };
|
||||
E86596452701612D00846EBD /* UIImageView+Vague.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "UIImageView+Vague.m"; sourceTree = "<group>"; };
|
||||
E865964F2701A1C000846EBD /* StatisticsService.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = StatisticsService.h; sourceTree = "<group>"; };
|
||||
E86596502701A1C000846EBD /* StatisticsService.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = StatisticsService.m; sourceTree = "<group>"; };
|
||||
E86596522701A55500846EBD /* StatisticsServiceHelper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = StatisticsServiceHelper.h; sourceTree = "<group>"; };
|
||||
@@ -581,8 +577,6 @@
|
||||
E89DA67127008D59008483C1 /* WalletInfoModel.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = WalletInfoModel.m; sourceTree = "<group>"; };
|
||||
E89DA67327009ACD008483C1 /* XPMineRechargeNavView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XPMineRechargeNavView.h; sourceTree = "<group>"; };
|
||||
E89DA67427009ACD008483C1 /* XPMineRechargeNavView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = XPMineRechargeNavView.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 /* UIImageConstant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = UIImageConstant.h; sourceTree = "<group>"; };
|
||||
E8AC720F26F43955007D6E91 /* UIImageConstant.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = UIImageConstant.m; sourceTree = "<group>"; };
|
||||
E8AC721126F46ADD007D6E91 /* XPMineSettingViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XPMineSettingViewController.h; sourceTree = "<group>"; };
|
||||
@@ -1422,8 +1416,6 @@
|
||||
children = (
|
||||
E86596422701611A00846EBD /* UIImage+ImageEffects.h */,
|
||||
E86596412701611A00846EBD /* UIImage+ImageEffects.m */,
|
||||
E86596442701612D00846EBD /* UIImageView+Vague.h */,
|
||||
E86596452701612D00846EBD /* UIImageView+Vague.m */,
|
||||
);
|
||||
path = VagueImageView;
|
||||
sourceTree = "<group>";
|
||||
@@ -1602,8 +1594,6 @@
|
||||
E8AC720A26F435AF007D6E91 /* UIImageView */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
E8AC720B26F435F5007D6E91 /* UIImageView+LoadImage.h */,
|
||||
E8AC720C26F435F5007D6E91 /* UIImageView+LoadImage.m */,
|
||||
E8AC720E26F43955007D6E91 /* UIImageConstant.h */,
|
||||
E8AC720F26F43955007D6E91 /* UIImageConstant.m */,
|
||||
1808072E27315E8E001FD836 /* NetImageView.h */,
|
||||
@@ -2201,7 +2191,6 @@
|
||||
186A534B26FC6ED900D67B2C /* TTPopupManagerService.m in Sources */,
|
||||
18E7B1B226E8AF980064BC9B /* MainPresenter.m in Sources */,
|
||||
E81366F626F0C0DF0076364C /* LoginFullInfoPresenter.m in Sources */,
|
||||
E86596462701612D00846EBD /* UIImageView+Vague.m in Sources */,
|
||||
189DD67E26E1FD8900AB55B1 /* UIImage+Utils.m in Sources */,
|
||||
E824545626F5E51900BE8163 /* XPMineVerifIdentityViewController.m in Sources */,
|
||||
186A534726FC6ED900D67B2C /* TTAlertConfig.m in Sources */,
|
||||
@@ -2215,7 +2204,6 @@
|
||||
E824543526F57D6E00BE8163 /* XPLoginVerifBindPhoneViewController.m in Sources */,
|
||||
E8680718271967B00024F48F /* MicroView.m in Sources */,
|
||||
E8B825CD26EA18C8009E8E9F /* ThemeColor.m in Sources */,
|
||||
E8AC720D26F435F5007D6E91 /* UIImageView+LoadImage.m in Sources */,
|
||||
E88B5CBD26FB3BDF00DA9178 /* XPTeenagerAlertView.m in Sources */,
|
||||
E8AEAEF327141C7C0017FCE0 /* XPRoomMessageContainerView.m in Sources */,
|
||||
E8AE427327153A3500BEEBB2 /* XPRoomActivityContainerView.m in Sources */,
|
||||
|
@@ -2,17 +2,35 @@
|
||||
// NetImageView.h
|
||||
// xplan-ios
|
||||
//
|
||||
// Created by apple on 2021/11/2.
|
||||
// Created by zu on 2021/11/2.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "UIImageView+LoadImage.h"
|
||||
#import "UIImageConstant.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
typedef void(^LoadCompletion)(UIImage *image, NSURL * url);
|
||||
|
||||
typedef NS_ENUM(NSInteger, NetImageState){
|
||||
NetImageStateUnload = 1,
|
||||
NetImageStateLoading,
|
||||
NetImageStateLoaded,
|
||||
};
|
||||
|
||||
@interface NetImageView : UIImageView
|
||||
|
||||
@property (nonatomic, copy) NSString * imgUrl;
|
||||
@property (nonatomic, assign, readonly) NetImageState state;
|
||||
@property (nonatomic, copy) NSString* imageUrl;
|
||||
@property (nonatomic, assign) ImageType imageType;
|
||||
@property (nonatomic, assign) CGFloat radius;
|
||||
|
||||
- (instancetype)initWithUrl:(NSString*)url;
|
||||
- (instancetype)initWithUrl:(NSString*)url type:(ImageType)type;
|
||||
- (instancetype)initWithUrl:(NSString*)url radius:(CGFloat)radius;
|
||||
- (instancetype)initWithUrl:(NSString*)url type:(ImageType)type radius:(CGFloat)radius;
|
||||
|
||||
- (void)loadImage:(UIImage * _Nullable)placeHolder completion:(LoadCompletion _Nullable)completion;
|
||||
|
||||
@end
|
||||
|
||||
|
@@ -2,12 +2,73 @@
|
||||
// NetImageView.m
|
||||
// xplan-ios
|
||||
//
|
||||
// Created by apple on 2021/11/2.
|
||||
// Created by zu on 2021/11/2.
|
||||
//
|
||||
|
||||
#import "NetImageView.h"
|
||||
#import <UIImageView+WebCache.h>
|
||||
#import <SDImageCache.h>
|
||||
|
||||
@interface NetImageView()
|
||||
|
||||
|
||||
@property (nonatomic, assign, readwrite) NetImageState state;
|
||||
@property (nonatomic, copy) NSString * innerConfigedUrl;
|
||||
|
||||
@end
|
||||
|
||||
@implementation NetImageView
|
||||
|
||||
- (instancetype)init {
|
||||
return [self initWithUrl:@"" type:-1 radius:0];
|
||||
}
|
||||
|
||||
- (instancetype)initWithUrl:(NSString *)url {
|
||||
return [self initWithUrl:url type:-1 radius:0];
|
||||
}
|
||||
|
||||
- (instancetype)initWithUrl:(NSString *)url type:(ImageType)type {
|
||||
return [self initWithUrl:url type:type radius:0];
|
||||
}
|
||||
|
||||
- (instancetype)initWithUrl:(NSString *)url radius:(CGFloat)radius {
|
||||
return [self initWithUrl:url type:-1 radius:radius];
|
||||
}
|
||||
|
||||
- (instancetype)initWithUrl:(NSString *)url type:(ImageType)type radius:(CGFloat)radius {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
_state = NetImageStateUnload;
|
||||
_imageType = type;
|
||||
_radius = radius;
|
||||
[self setImageUrl:url];
|
||||
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)loadImage:(UIImage *)placeHolder completion:(LoadCompletion)completion {
|
||||
self.state = NetImageStateLoading;
|
||||
[self sd_setImageWithURL:[NSURL URLWithString:_innerConfigedUrl] placeholderImage:placeHolder options:SDWebImageRetryFailed completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
|
||||
self.state = NetImageStateLoaded;
|
||||
if (completion) {
|
||||
completion(image, imageURL);
|
||||
return;
|
||||
};
|
||||
}];
|
||||
}
|
||||
|
||||
// TODO: [setImageUrl] 和 [loadImage] 重复加载,需要逻辑优化。
|
||||
- (void)setImageUrl:(NSString *)url {
|
||||
_imageUrl = url;
|
||||
_innerConfigedUrl = [UIImageConstant configUrl:_imageUrl type:self.imageType radius:self.radius];
|
||||
UIImage * image = [[SDImageCache sharedImageCache] imageFromCacheForKey:_innerConfigedUrl];
|
||||
if (image) {
|
||||
self.image = image;
|
||||
self.state = NetImageStateLoaded;
|
||||
} else {
|
||||
[self loadImage:nil completion:nil];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
@@ -20,7 +20,7 @@ UIKIT_EXTERN NSString * const kImageTypeUserLibaryDetail;//用户相册大图nil
|
||||
UIKIT_EXTERN NSString * const kImageTypeCornerAvatar;//圆角图形,会先把图形裁剪成正方形,并且转换为png
|
||||
UIKIT_EXTERN NSString * const kImageTypeUserInfoAlbum;//用户信息里面相册
|
||||
|
||||
typedef NS_ENUM(NSUInteger,ImageType){
|
||||
typedef NS_ENUM(NSUInteger, ImageType){
|
||||
ImageTypeRoomFace = 1, //房间表情
|
||||
ImageTypeRoomGift, //房间礼物
|
||||
ImageTypeUserIcon, //用户头像60x60
|
||||
@@ -38,7 +38,9 @@ typedef NS_ENUM(NSUInteger,ImageType){
|
||||
/// banner的占位图
|
||||
+ (UIImage *)defalutBannerPlaceholder;
|
||||
|
||||
|
||||
+ (NSString*)configUrl:(NSString*)url type:(ImageType)type;
|
||||
+ (NSString*)configUrl:(NSString*)url radius:(CGFloat)radius;
|
||||
+ (NSString*)configUrl:(NSString*)url type:(ImageType)type radius:(CGFloat)radius;
|
||||
|
||||
@end
|
||||
|
||||
|
@@ -9,24 +9,84 @@
|
||||
|
||||
@implementation UIImageConstant
|
||||
|
||||
|
||||
NSString * const kImageTypeRoomFace = @""; //房间表情
|
||||
NSString * const kImageTypeRoomGift = @""; //房间礼物
|
||||
NSString * const kImageTypeUserIcon = @"imageMogr2/auto-orient/thumbnail/150x150"; //用户头像150x150
|
||||
NSString * const kImageTypeUserLibaryDetail = @"imageMogr2/auto-orient/thumbnail/300x300"; //用户相册大图nil
|
||||
/// 房间表情
|
||||
NSString * const kImageTypeRoomFace = @"";
|
||||
/// 房间礼物
|
||||
NSString * const kImageTypeRoomGift = @"";
|
||||
/// 用户头像150x150
|
||||
NSString * const kImageTypeUserIcon = @"imageMogr2/auto-orient/thumbnail/150x150";
|
||||
/// 用户相册大图
|
||||
NSString * const kImageTypeUserLibaryDetail = @"imageMogr2/auto-orient/thumbnail/300x300";
|
||||
NSString * const kImageTypeCornerAvatar = @"imageMogr2/auto-orient/thumbnail/300x300/format/png";
|
||||
NSString * const kImageTypeUserInfoAlbum = @"imageMogr2/auto-orient/thumbnail/375x248"; ;//用户信息里面相册
|
||||
/// 用户信息里面相册
|
||||
NSString * const kImageTypeUserInfoAlbum = @"imageMogr2/auto-orient/thumbnail/375x248"; ;
|
||||
|
||||
/// 头像的默认占位图
|
||||
+ (UIImage *)defaultAvatarPlaceholder {
|
||||
return [UIImage imageNamed:@"common_avatar"];
|
||||
return [UIImage imageNamed:@"common_avatar"];
|
||||
}
|
||||
/// 空白图的占位图
|
||||
+ (UIImage *)defalutEmptyPlaceholder {
|
||||
return [UIImage imageNamed:@"common_empty"];
|
||||
return [UIImage imageNamed:@"common_empty"];
|
||||
}
|
||||
/// banner的占位图
|
||||
+ (UIImage *)defalutBannerPlaceholder {
|
||||
return [UIImage imageNamed:@"common_banner"];
|
||||
return [UIImage imageNamed:@"common_banner"];
|
||||
}
|
||||
|
||||
+ (NSString *)configUrl:(NSString *)url type:(ImageType)type {
|
||||
return [self configUrl:url type:type radius:0];
|
||||
}
|
||||
|
||||
+ (NSString *)configUrl:(NSString *)url radius:(CGFloat)radius {
|
||||
return [self configUrl:url type:-1 radius:radius];
|
||||
}
|
||||
|
||||
+ (NSString *)configUrl:(NSString *)url type:(ImageType)type radius:(CGFloat)radius {
|
||||
if (!url || url.length <= 0) return nil;
|
||||
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;
|
||||
case ImageTypeUserInfoAlbum:
|
||||
configUrl = kImageTypeUserInfoAlbum;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (configUrl) {
|
||||
if ([url containsString:@"?"]) {
|
||||
[urlString appendString:@"|"];
|
||||
}else{
|
||||
[urlString appendString:@"?"];
|
||||
}
|
||||
[urlString appendString:configUrl];
|
||||
}
|
||||
|
||||
if (radius > 0) {
|
||||
[urlString appendString:[NSString stringWithFormat:@"|roundPic/radius/%f", radius]];
|
||||
}
|
||||
|
||||
return CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,
|
||||
(CFStringRef)urlString,
|
||||
NULL,
|
||||
(CFStringRef)@"|",
|
||||
kCFStringEncodingUTF8));
|
||||
}
|
||||
|
||||
@end
|
||||
|
@@ -1,57 +0,0 @@
|
||||
//
|
||||
// UIImageView+LoadImage.h
|
||||
// xplan-ios
|
||||
//
|
||||
// Created by 冯硕 on 2021/9/17.
|
||||
// 加载图片的类
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "UIImageConstant.h"
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
typedef void(^LoadImageSuccess)(UIImage *image, NSURL * url);
|
||||
|
||||
@interface UIImageView (LoadImage)
|
||||
/// 加载图片
|
||||
/// @param url 图片的链接地址
|
||||
/// @param placeholderImage 站位图
|
||||
/// @param type 类型 用于设置大小
|
||||
/// @param cornerRadious 弧度
|
||||
/// @param complection 成功的回调
|
||||
- (void)load_imageWithUrl:(NSString *)url
|
||||
placeholderImage:(UIImage *)placeholderImage
|
||||
type:(ImageType)type
|
||||
cornerRadious:(CGFloat)cornerRadious
|
||||
complection:(nullable LoadImageSuccess)complection;
|
||||
|
||||
/// 加载图片 回调图片的
|
||||
/// @param url 图片的链接地址
|
||||
/// @param placeholderImage 站位图
|
||||
/// @param complection 成功了
|
||||
- (void)load_imageWithUrl:(NSString *)url placeholderImage:(UIImage *)placeholderImage type:(ImageType)type complection:(nullable LoadImageSuccess)complection;
|
||||
|
||||
/// 加载图片不需要成功的回调
|
||||
/// @param url 图片的链接地址
|
||||
/// @param placeholderImage 站位图
|
||||
/// @param type 类型 用于设置大小
|
||||
/// @param cornerRadious 弧度
|
||||
- (void)load_imageWithUrl:(NSString *)url
|
||||
placeholderImage:(UIImage *)placeholderImage
|
||||
type:(ImageType)type
|
||||
cornerRadious:(CGFloat)cornerRadious;
|
||||
|
||||
/// 加载图片 没有圆角的设置
|
||||
/// @param url 图片的链接地址
|
||||
/// @param placeholderImage 站位图
|
||||
/// @param type 类型 用于设置大小
|
||||
- (void)load_imageWithUrl:(NSString *)url placeholderImage:(UIImage *)placeholderImage type:(ImageType)type;
|
||||
|
||||
/// 加载图片 没有类型的设置
|
||||
/// @param url 图片的链接地址
|
||||
/// @param placeholderImage 站位图
|
||||
- (void)load_imageWithUrl:(NSString *)url placeholderImage:(UIImage *)placeholderImage;
|
||||
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
@@ -1,143 +0,0 @@
|
||||
//
|
||||
// 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 complection 成功的回调
|
||||
- (void)load_imageWithUrl:(NSString *)url
|
||||
placeholderImage:(UIImage *)placeholderImage
|
||||
type:(ImageType)type
|
||||
cornerRadious:(CGFloat)cornerRadious
|
||||
complection:(nullable LoadImageSuccess)complection {
|
||||
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;
|
||||
case ImageTypeUserInfoAlbum:
|
||||
{
|
||||
configUrl = kImageTypeUserInfoAlbum;
|
||||
}
|
||||
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) {
|
||||
[self sd_setImageWithURL:[NSURL URLWithString:encodeStr] placeholderImage:placeholderImage options:SDWebImageRetryFailed completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
|
||||
if (complection) {
|
||||
complection(image, imageURL);
|
||||
}
|
||||
}];
|
||||
}else{
|
||||
[self sd_setImageWithURL:[NSURL URLWithString:encodeStr] placeholderImage:nil options:SDWebImageRetryFailed completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
|
||||
if (complection) {
|
||||
complection(image, imageURL);
|
||||
}
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// 加载图片不需要成功的回调
|
||||
/// @param url 图片的链接地址
|
||||
/// @param placeholderImage 站位图
|
||||
/// @param type 类型 用于设置大小
|
||||
/// @param cornerRadious 弧度
|
||||
- (void)load_imageWithUrl:(NSString *)url
|
||||
placeholderImage:(UIImage *)placeholderImage
|
||||
type:(ImageType)type
|
||||
cornerRadious:(CGFloat)cornerRadious {
|
||||
[self load_imageWithUrl:url placeholderImage:placeholderImage type:type cornerRadious:cornerRadious complection:nil];
|
||||
}
|
||||
|
||||
|
||||
/// 加载图片 没有圆角的设置
|
||||
/// @param url 图片的链接地址
|
||||
/// @param placeholderImage 站位图
|
||||
/// @param type 类型 用于设置大小
|
||||
- (void)load_imageWithUrl:(NSString *)url placeholderImage:(UIImage *)placeholderImage type:(ImageType)type{
|
||||
[self load_imageWithUrl:url placeholderImage:placeholderImage type:type cornerRadious:0];
|
||||
}
|
||||
|
||||
/// 加载图片 没有类型的设置
|
||||
/// @param url 图片的链接地址
|
||||
/// @param placeholderImage 站位图
|
||||
- (void)load_imageWithUrl:(NSString *)url placeholderImage:(UIImage *)placeholderImage {
|
||||
[self load_imageWithUrl:url placeholderImage:placeholderImage type:0 cornerRadious:0];
|
||||
}
|
||||
|
||||
|
||||
/// 加载图片 回调图片的
|
||||
/// @param url 图片的链接地址
|
||||
/// @param placeholderImage 站位图
|
||||
/// @param complection 成功了
|
||||
- (void)load_imageWithUrl:(NSString *)url placeholderImage:(UIImage *)placeholderImage type:(ImageType)type complection:(nullable LoadImageSuccess)complection{
|
||||
[self load_imageWithUrl:url placeholderImage:placeholderImage type:type cornerRadious:0 complection:complection];
|
||||
}
|
||||
|
||||
- (NSString *)URLEncodedString:(NSString *)string
|
||||
{
|
||||
|
||||
NSString *encodedString = (NSString *)
|
||||
CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,
|
||||
(CFStringRef)string,
|
||||
NULL,
|
||||
(CFStringRef)@"|",
|
||||
kCFStringEncodingUTF8));
|
||||
|
||||
return encodedString;
|
||||
}
|
||||
|
||||
@end
|
@@ -1,20 +0,0 @@
|
||||
//
|
||||
// UIImageView+Vague.h
|
||||
// xplan-ios
|
||||
//
|
||||
// Created by 冯硕 on 2021/9/27.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface UIImageView (Vague)
|
||||
/// 模糊的效果
|
||||
/// @param image 需要模糊的图片
|
||||
/// @param blurRadius 角度 越大 模糊的越不明显 默认20
|
||||
- (void)setImageToBlur:(UIImage *)image
|
||||
blurRadius:(CGFloat)blurRadius;
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
@@ -1,34 +0,0 @@
|
||||
//
|
||||
// UIImageView+Vague.m
|
||||
// xplan-ios
|
||||
//
|
||||
// Created by 冯硕 on 2021/9/27.
|
||||
//
|
||||
|
||||
#import "UIImageView+Vague.h"
|
||||
#import "UIImage+ImageEffects.h"
|
||||
@implementation UIImageView (Vague)
|
||||
|
||||
/// 模糊的效果
|
||||
/// @param image 需要模糊的图片
|
||||
/// @param blurRadius 角度 越大 模糊的越明显 默认20
|
||||
- (void)setImageToBlur:(UIImage *)image
|
||||
blurRadius:(CGFloat)blurRadius {
|
||||
NSParameterAssert(image);
|
||||
if (blurRadius < 0) {
|
||||
blurRadius = 20;
|
||||
}
|
||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
||||
|
||||
UIImage *blurredImage = [image applyBlurWithRadius:blurRadius
|
||||
tintColor:nil
|
||||
saturationDeltaFactor:1.8
|
||||
maskImage:nil];
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
self.image = blurredImage;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@end
|
@@ -9,10 +9,13 @@
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
/** 支持 NetImageView 的 YYLabel。
|
||||
*
|
||||
* - 使用者不再需要处理富文本的网络图片。
|
||||
* - 使用场景目前还有较多局限性。
|
||||
*/
|
||||
@interface NetImageYYLabel : YYLabel
|
||||
|
||||
- (void)loadAttributedText:(NSAttributedString *)attributedText load:(BOOL)load;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
@@ -10,32 +10,42 @@
|
||||
|
||||
@implementation NetImageYYLabel
|
||||
|
||||
- (void)loadAttributedText:(NSAttributedString *)attributedText load:(BOOL)load {
|
||||
[super setAttributedText:attributedText];
|
||||
if (load ) {
|
||||
NSUInteger length = attributedText.length;
|
||||
for (int i = 0; i < length; i++) {
|
||||
NSRange range = NSMakeRange(0, 0);
|
||||
NSDictionary* attr = [attributedText attributesAtIndex:i effectiveRange:&range];
|
||||
YYTextAttachment* attachment = attr[YYTextAttachmentAttributeName];
|
||||
if (!attachment || ![attachment.content isKindOfClass:[NetImageView class]]) continue;
|
||||
|
||||
NetImageView* imageView = attachment.content;
|
||||
if (!imageView.imgUrl) continue;
|
||||
|
||||
[imageView load_imageWithUrl:imageView.imgUrl placeholderImage:[UIImageConstant defaultAvatarPlaceholder] type:ImageTypeUserIcon complection:^(UIImage * _Nonnull image, NSURL * _Nonnull url) {
|
||||
CGFloat kscale = (CGFloat)imageView.image.size.width / (CGFloat)imageView.image.size.height; // 默认根据高度等比例缩小
|
||||
imageView.frame = CGRectMake(0, 0, imageView.frame.size.height * kscale, imageView.frame.size.height);
|
||||
NSMutableAttributedString * replaceAttr = [NSMutableAttributedString yy_attachmentStringWithContent:imageView contentMode:UIViewContentModeScaleAspectFit attachmentSize:imageView.frame.size alignToFont:[UIFont systemFontOfSize:14.0] alignment:YYTextVerticalAlignmentCenter];
|
||||
|
||||
NSMutableAttributedString * attribute = [self.attributedText mutableCopy];
|
||||
[attribute replaceCharactersInRange:range withAttributedString:replaceAttr];
|
||||
|
||||
[super setAttributedText:nil];
|
||||
[super setAttributedText:attribute];
|
||||
}];
|
||||
- (void)setAttributedText:(NSAttributedString *)attributedText {
|
||||
NSUInteger length = attributedText.length;
|
||||
NSAttributedString* attributedTextCopy = [attributedText mutableCopy];
|
||||
for (int i = 0; i < length; i++) {
|
||||
YYTextAttachment* attachment = [attributedText yy_attributesAtIndex:i][YYTextAttachmentAttributeName];
|
||||
if (!attachment || ![attachment.content isKindOfClass:[NetImageView class]]) continue;
|
||||
NetImageView* imageView = attachment.content;
|
||||
if (!imageView.imageUrl) continue;
|
||||
|
||||
if (imageView.state == NetImageStateLoaded) {
|
||||
attributedTextCopy = [self updateNetImageAttribute:imageView attributes:attributedTextCopy index:i];
|
||||
continue;
|
||||
}
|
||||
|
||||
[imageView loadImage:[UIImageConstant defalutEmptyPlaceholder] completion:^(UIImage * _Nonnull image, NSURL * _Nonnull url) {
|
||||
imageView.image = image;
|
||||
[super setAttributedText:[self updateNetImageAttribute:imageView attributes:self.attributedText index:i]];
|
||||
}];
|
||||
}
|
||||
[super setAttributedText:attributedTextCopy];
|
||||
}
|
||||
|
||||
- (NSAttributedString*)updateNetImageAttribute:(NetImageView*)imageView attributes:(NSAttributedString*)attributes index:(NSInteger)index{
|
||||
UIImage* image = imageView.image;
|
||||
CGFloat scale = image.size.width / image.size.height;
|
||||
// 目前是根据原高度(imageView.bounds.size.height)等比例缩放图片。
|
||||
CGSize size = CGSizeMake(imageView.bounds.size.height * scale, imageView.bounds.size.height);
|
||||
imageView.bounds = CGRectMake(0, 0, size.width, size.height);
|
||||
|
||||
NSMutableAttributedString * replaceAttr = [NSMutableAttributedString yy_attachmentStringWithContent:imageView contentMode:UIViewContentModeScaleAspectFit attachmentSize:size alignToFont:[UIFont systemFontOfSize:15.0] alignment:YYTextVerticalAlignmentCenter];
|
||||
|
||||
NSRange range;
|
||||
NSMutableAttributedString* copy = [attributes mutableCopy];
|
||||
[copy attributesAtIndex:index effectiveRange:&range];
|
||||
[copy replaceCharactersInRange:range withAttributedString:replaceAttr];
|
||||
return copy;
|
||||
}
|
||||
|
||||
@end
|
||||
|
@@ -10,13 +10,14 @@
|
||||
#import <Masonry/Masonry.h>
|
||||
///Tool
|
||||
#import "UIButton+EnlargeTouchArea.h"
|
||||
#import "UIImageView+LoadImage.h"
|
||||
///Model
|
||||
#import "UserPhoto.h"
|
||||
|
||||
#import "NetImageView.h"
|
||||
|
||||
@interface XPMineUserInfoAlbumCollectionViewCell ()
|
||||
///
|
||||
@property (nonatomic,strong) UIImageView *logoImageView;
|
||||
@property (nonatomic,strong) NetImageView *logoImageView;
|
||||
///
|
||||
@property (nonatomic,strong) UIButton *deleteButton;
|
||||
@end
|
||||
@@ -58,7 +59,7 @@
|
||||
- (void)setPhoto:(UserPhoto *)photo {
|
||||
_photo = photo;
|
||||
if (_photo) {
|
||||
[self.logoImageView load_imageWithUrl:_photo.photoUrl placeholderImage:[UIImageConstant defaultAvatarPlaceholder] type:ImageTypeUserLibaryDetail];
|
||||
self.logoImageView.imageUrl = photo.photoUrl;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,12 +75,13 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (UIImageView *)logoImageView {
|
||||
- (NetImageView *)logoImageView {
|
||||
if (!_logoImageView) {
|
||||
_logoImageView = [[UIImageView alloc] init];
|
||||
_logoImageView = [[NetImageView alloc] init];
|
||||
_logoImageView.userInteractionEnabled = YES;
|
||||
_logoImageView.layer.cornerRadius = 5;
|
||||
_logoImageView.layer.masksToBounds = YES;
|
||||
_logoImageView.imageType = ImageTypeUserLibaryDetail;
|
||||
_logoImageView.contentMode = UIViewContentModeScaleAspectFill;
|
||||
}
|
||||
return _logoImageView;
|
||||
|
@@ -10,18 +10,19 @@
|
||||
#import <Masonry/Masonry.h>
|
||||
///Tool
|
||||
#import "ThemeColor.h"
|
||||
#import "UIImageView+LoadImage.h"
|
||||
///Model
|
||||
#import "XPMineUserInfoEditModel.h"
|
||||
#import "UserPhoto.h"
|
||||
|
||||
#import "NetImageView.h"
|
||||
|
||||
@interface XPMineUserInfoEditTableViewCell ()
|
||||
///容器
|
||||
@property (nonatomic,strong) UIStackView *stackView;
|
||||
///标题
|
||||
@property (nonatomic,strong) UILabel *titleLabel;
|
||||
///头像
|
||||
@property (nonatomic,strong) UIImageView *avatarImageView;
|
||||
@property (nonatomic,strong) NetImageView *avatarImageView;
|
||||
///副标题
|
||||
@property (nonatomic,strong) UILabel *subTitleLabel;
|
||||
///箭头
|
||||
@@ -29,11 +30,11 @@
|
||||
///相册的
|
||||
@property (nonatomic,strong) UIStackView *phototStackView;
|
||||
///第一个
|
||||
@property (nonatomic,strong) UIImageView *firstPhotoImageView;
|
||||
///第er个
|
||||
@property (nonatomic,strong) UIImageView *secondPhotoImageView;
|
||||
@property (nonatomic,strong) NetImageView *firstPhotoImageView;
|
||||
///第二个
|
||||
@property (nonatomic,strong) NetImageView *secondPhotoImageView;
|
||||
///第三个
|
||||
@property (nonatomic,strong) UIImageView *thirdPhotoImageView;
|
||||
@property (nonatomic,strong) NetImageView *thirdPhotoImageView;
|
||||
///分割线
|
||||
@property (nonatomic,strong) UIView * partLineView;
|
||||
///
|
||||
@@ -111,9 +112,9 @@
|
||||
array = [array subarrayWithRange:NSMakeRange(0, 3)];
|
||||
}
|
||||
for (int i = 0; i < array.count; i++) {
|
||||
UIImageView * imageView = [self.photoViewArray objectAtIndex:i];
|
||||
NetImageView * imageView = [self.photoViewArray objectAtIndex:i];
|
||||
NSString * imageUrl = [array objectAtIndex:i].photoUrl;
|
||||
[imageView load_imageWithUrl:imageUrl placeholderImage:[UIImageConstant defaultAvatarPlaceholder] type:ImageTypeUserIcon];
|
||||
imageView.imageUrl = imageUrl;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,7 +126,7 @@
|
||||
self.phototStackView.hidden = YES;
|
||||
self.avatarImageView.hidden = NO;
|
||||
if (model.avatarUrl.length > 0) {
|
||||
[self.avatarImageView load_imageWithUrl:model.avatarUrl placeholderImage:[UIImageConstant defaultAvatarPlaceholder] type:ImageTypeUserIcon];
|
||||
self.avatarImageView.imageUrl = model.avatarUrl;
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -205,12 +206,14 @@
|
||||
return _subTitleLabel;
|
||||
}
|
||||
|
||||
- (UIImageView *)avatarImageView {
|
||||
- (NetImageView *)avatarImageView {
|
||||
if (!_avatarImageView) {
|
||||
_avatarImageView = [[UIImageView alloc] init];
|
||||
_avatarImageView = [[NetImageView alloc] init];
|
||||
_avatarImageView.userInteractionEnabled = YES;
|
||||
_avatarImageView.layer.cornerRadius = 25;
|
||||
_avatarImageView.layer.masksToBounds = YES;
|
||||
_avatarImageView.image = [UIImageConstant defaultAvatarPlaceholder];
|
||||
_avatarImageView.imageType = ImageTypeUserIcon;
|
||||
}
|
||||
return _avatarImageView;
|
||||
}
|
||||
@@ -236,32 +239,38 @@
|
||||
return _phototStackView;
|
||||
}
|
||||
|
||||
- (UIImageView *)firstPhotoImageView {
|
||||
- (NetImageView *)firstPhotoImageView {
|
||||
if (!_firstPhotoImageView) {
|
||||
_firstPhotoImageView = [[UIImageView alloc] init];
|
||||
_firstPhotoImageView = [[NetImageView alloc] init];
|
||||
_firstPhotoImageView.userInteractionEnabled = YES;
|
||||
_firstPhotoImageView.layer.masksToBounds = YES;
|
||||
_firstPhotoImageView.layer.cornerRadius = 5;
|
||||
_firstPhotoImageView.imageType = ImageTypeUserIcon;
|
||||
_firstPhotoImageView.image = [UIImageConstant defaultAvatarPlaceholder];
|
||||
}
|
||||
return _firstPhotoImageView;
|
||||
}
|
||||
|
||||
- (UIImageView *)secondPhotoImageView {
|
||||
- (NetImageView *)secondPhotoImageView {
|
||||
if (!_secondPhotoImageView) {
|
||||
_secondPhotoImageView = [[UIImageView alloc] init];
|
||||
_secondPhotoImageView = [[NetImageView alloc] init];
|
||||
_secondPhotoImageView.userInteractionEnabled = YES;
|
||||
_secondPhotoImageView.layer.masksToBounds = YES;
|
||||
_secondPhotoImageView.layer.cornerRadius = 5;
|
||||
_secondPhotoImageView.imageType = ImageTypeUserIcon;
|
||||
_secondPhotoImageView.image = [UIImageConstant defaultAvatarPlaceholder];
|
||||
}
|
||||
return _secondPhotoImageView;
|
||||
}
|
||||
|
||||
- (UIImageView *)thirdPhotoImageView {
|
||||
- (NetImageView *)thirdPhotoImageView {
|
||||
if (!_thirdPhotoImageView) {
|
||||
_thirdPhotoImageView = [[UIImageView alloc] init];
|
||||
_thirdPhotoImageView = [[NetImageView alloc] init];
|
||||
_thirdPhotoImageView.userInteractionEnabled = YES;
|
||||
_thirdPhotoImageView.layer.masksToBounds = YES;
|
||||
_thirdPhotoImageView.layer.cornerRadius = 5;
|
||||
_thirdPhotoImageView.imageType = ImageTypeUserIcon;
|
||||
_thirdPhotoImageView.image = [UIImageConstant defaultAvatarPlaceholder];
|
||||
}
|
||||
return _thirdPhotoImageView;
|
||||
}
|
||||
|
@@ -14,14 +14,15 @@
|
||||
///Tool
|
||||
#import "ThemeColor.h"
|
||||
#import "XPMacro.h"
|
||||
#import "UIImageView+LoadImage.h"
|
||||
#import "UIImageView+Vague.h"
|
||||
#import "UIImage+ImageEffects.h"
|
||||
///Model
|
||||
#import "UserInfoModel.h"
|
||||
|
||||
#import "NetImageView.h"
|
||||
|
||||
@interface XPMineUserInfoImageCollectionViewCell : UICollectionViewCell
|
||||
///
|
||||
@property (nonatomic,strong) UIImageView *logoImageView;
|
||||
@property (nonatomic,strong) NetImageView *logoImageView;
|
||||
@end
|
||||
|
||||
@implementation XPMineUserInfoImageCollectionViewCell
|
||||
@@ -48,13 +49,14 @@
|
||||
}
|
||||
|
||||
#pragma mark - Getters And Setters
|
||||
- (UIImageView *)logoImageView {
|
||||
- (NetImageView *)logoImageView {
|
||||
if (!_logoImageView) {
|
||||
_logoImageView = [[UIImageView alloc] init];
|
||||
_logoImageView = [[NetImageView alloc] init];
|
||||
_logoImageView.userInteractionEnabled = YES;
|
||||
_logoImageView.layer.masksToBounds = YES;
|
||||
_logoImageView.contentMode = UIViewContentModeScaleAspectFill;
|
||||
_logoImageView.tag = 100000;
|
||||
_logoImageView.imageType = ImageTypeUserInfoAlbum;
|
||||
}
|
||||
return _logoImageView;
|
||||
}
|
||||
@@ -129,15 +131,22 @@
|
||||
}
|
||||
|
||||
- (void)setupCustomCell:(UICollectionViewCell *)cell forIndex:(NSInteger)index cycleScrollView:(SDCycleScrollView *)view {
|
||||
XPMineUserInfoImageCollectionViewCell * imageCell = (XPMineUserInfoImageCollectionViewCell *)cell;
|
||||
NSString *url = [self.imageUrls objectAtIndex:index];
|
||||
@weakify(imageCell);
|
||||
[imageCell.logoImageView load_imageWithUrl:url placeholderImage:[UIImageConstant defalutBannerPlaceholder] type:ImageTypeUserInfoAlbum complection:^(UIImage * _Nonnull image, NSURL * _Nonnull url) {
|
||||
@strongify(imageCell);
|
||||
if (image) {
|
||||
[imageCell.logoImageView setImageToBlur:image blurRadius:45];
|
||||
}
|
||||
}];
|
||||
XPMineUserInfoImageCollectionViewCell * imageCell = (XPMineUserInfoImageCollectionViewCell *)cell;
|
||||
NSString *url = [self.imageUrls objectAtIndex:index];
|
||||
@weakify(imageCell);
|
||||
imageCell.logoImageView.imageUrl = url;
|
||||
[imageCell.logoImageView loadImage:imageCell.logoImageView.image completion:^(UIImage * _Nonnull image, NSURL * _Nonnull url) {
|
||||
@strongify(imageCell);
|
||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
||||
UIImage *blurredImage = [image applyBlurWithRadius:45
|
||||
tintColor:nil
|
||||
saturationDeltaFactor:1.8
|
||||
maskImage:nil];
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
imageCell.logoImageView.image = blurredImage;
|
||||
});
|
||||
});
|
||||
}];
|
||||
}
|
||||
|
||||
-(void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didScrollToIndex:(NSInteger)index {
|
||||
|
@@ -12,15 +12,15 @@
|
||||
///Tool
|
||||
#import "ThemeColor.h"
|
||||
#import "XPMacro.h"
|
||||
#import "UIImageView+LoadImage.h"
|
||||
///View
|
||||
#import "XPMineAccountView.h"
|
||||
#import "NetImageView.h"
|
||||
///Model
|
||||
#import "UserInfoModel.h"
|
||||
|
||||
@interface XPMineHeadView ()
|
||||
///头像
|
||||
@property (nonatomic,strong) UIImageView * avatarImageView;
|
||||
@property (nonatomic,strong) NetImageView * avatarImageView;
|
||||
///name的容器
|
||||
@property (nonatomic,strong) UIStackView *nameStackView;
|
||||
///名字
|
||||
@@ -129,7 +129,7 @@
|
||||
if (_userInfo) {
|
||||
self.idLabel.text = [NSString stringWithFormat:@"音游号:%ld", (long)_userInfo.erbanNo];
|
||||
self.nameLabel.text = _userInfo.nick.length > 0 ? _userInfo.nick : @"";
|
||||
[self.avatarImageView load_imageWithUrl:_userInfo.avatar placeholderImage:[UIImageConstant defaultAvatarPlaceholder] type:ImageTypeUserIcon];
|
||||
self.avatarImageView.imageUrl = userInfo.avatar;
|
||||
NSString * sexName;
|
||||
if (userInfo.gender == GenderType_Male) {
|
||||
sexName = @"common_male";
|
||||
@@ -139,12 +139,14 @@
|
||||
self.sexImageView.image = [UIImage imageNamed:sexName];
|
||||
}
|
||||
}
|
||||
- (UIImageView *)avatarImageView {
|
||||
- (NetImageView *)avatarImageView {
|
||||
if (!_avatarImageView) {
|
||||
_avatarImageView = [[UIImageView alloc] init];
|
||||
_avatarImageView = [[NetImageView alloc] init];
|
||||
_avatarImageView.userInteractionEnabled = YES;
|
||||
_avatarImageView.layer.masksToBounds = YES;
|
||||
_avatarImageView.layer.cornerRadius = 25;
|
||||
_avatarImageView.image = [UIImageConstant defaultAvatarPlaceholder];
|
||||
_avatarImageView.imageType = ImageTypeUserIcon;
|
||||
}
|
||||
return _avatarImageView;
|
||||
}
|
||||
|
@@ -17,98 +17,98 @@
|
||||
#import "NetImageView.h"
|
||||
|
||||
@implementation XPRoomMessageAttributeHelper
|
||||
|
||||
/// 文本类的消息的富文本
|
||||
/// @param remoteModel 扩展字段中的内容
|
||||
/// @param nick 名字
|
||||
+ (NSMutableAttributedString *)createLevelTextAttribute:(XPMessageRemoteExtModel *)remoteModel nick:(NSString *)nick text:(NSString *)text {
|
||||
NSMutableAttributedString * attribute = [[NSMutableAttributedString alloc] init];
|
||||
if (remoteModel.defUser == UserLevelType_Offical) {
|
||||
NSMutableAttributedString * offcialAttribute = [self createLocalImageAttribute:@"common_offical" size:CGSizeMake(13, 13)];
|
||||
[attribute appendAttributedString:offcialAttribute];
|
||||
[attribute appendAttributedString:[self createSapceAttribute:2]];
|
||||
}
|
||||
|
||||
if (remoteModel.newUser) {
|
||||
NSMutableAttributedString * newUserAttribute = [self createLocalImageAttribute:@"common_new_user" size:CGSizeMake(13, 13)];
|
||||
[attribute appendAttributedString:newUserAttribute];
|
||||
[attribute appendAttributedString:[self createSapceAttribute:2]];
|
||||
}
|
||||
|
||||
if (remoteModel.experUrl) {
|
||||
UIImage * image = [self cacheImage:remoteModel.experUrl type:ImageTypeUserIcon];
|
||||
NSMutableAttributedString * experAttribute;
|
||||
if (image) {
|
||||
CGFloat kscale = image.size.width / image.size.height;
|
||||
experAttribute = [self createImageAttribute:image size:CGSizeMake(16 * kscale, 16)];
|
||||
} else {
|
||||
experAttribute = [self createUrlImageAttribute:remoteModel.experUrl size:CGSizeMake(25, 16)];
|
||||
}
|
||||
[attribute appendAttributedString:experAttribute];
|
||||
[attribute appendAttributedString:[self createSapceAttribute:2]];
|
||||
}
|
||||
|
||||
NSMutableAttributedString * nickAttribute = [self createTextAttribute:nick titleColor:[ThemeColor messageDefaultTextColor] font:kRoomMessageDefalutFont];
|
||||
[attribute appendAttributedString:nickAttribute];
|
||||
[attribute appendAttributedString:[self createSapceAttribute:2]];
|
||||
|
||||
NSMutableAttributedString * textAttribute = [self createTextAttribute:text titleColor:[ThemeColor messageTextColor] font:kRoomMessageDefalutFont];
|
||||
[attribute appendAttributedString:textAttribute];
|
||||
return attribute;
|
||||
NSMutableAttributedString * attribute = [[NSMutableAttributedString alloc] init];
|
||||
if (remoteModel.defUser == UserLevelType_Offical) {
|
||||
NSMutableAttributedString * offcialAttribute = [self createLocalImageAttribute:@"common_offical" size:CGSizeMake(13, 13)];
|
||||
[attribute appendAttributedString:offcialAttribute];
|
||||
[attribute appendAttributedString:[self createSapceAttribute:2]];
|
||||
}
|
||||
|
||||
if (remoteModel.newUser) {
|
||||
NSMutableAttributedString * newUserAttribute = [self createLocalImageAttribute:@"common_new_user" size:CGSizeMake(13, 13)];
|
||||
[attribute appendAttributedString:newUserAttribute];
|
||||
[attribute appendAttributedString:[self createSapceAttribute:2]];
|
||||
}
|
||||
|
||||
if (remoteModel.experUrl) {
|
||||
NSMutableAttributedString * experAttribute = [self createUrlImageAttribute:remoteModel.experUrl size:CGSizeMake(25, 16)];
|
||||
[attribute appendAttributedString:experAttribute];
|
||||
[attribute appendAttributedString:[self createSapceAttribute:2]];
|
||||
}
|
||||
|
||||
NSMutableAttributedString * nickAttribute = [self createTextAttribute:nick titleColor:[ThemeColor messageDefaultTextColor] font:kRoomMessageDefalutFont];
|
||||
[attribute appendAttributedString:nickAttribute];
|
||||
[attribute appendAttributedString:[self createSapceAttribute:2]];
|
||||
|
||||
NSMutableAttributedString * textAttribute = [self createTextAttribute:text titleColor:[ThemeColor messageTextColor] font:kRoomMessageDefalutFont];
|
||||
[attribute appendAttributedString:textAttribute];
|
||||
return attribute;
|
||||
}
|
||||
|
||||
|
||||
/// 进入房间的富文本 NIMChatroomEventTypeEnter
|
||||
/// @param nick 进入房间的名称
|
||||
+ (NSMutableAttributedString *)createUserEnterRoomAttribute:(NSString *)nick {
|
||||
nick = nick.length > 0 ? nick : @"";
|
||||
NSMutableAttributedString * attribute = [[NSMutableAttributedString alloc] init];
|
||||
NSMutableAttributedString * nickAttribute = [self createTextAttribute:nick titleColor:[ThemeColor messageNickColor] font:kRoomMessageDefalutFont];
|
||||
NSMutableAttributedString * enterRoomAttribute = [self createTextAttribute:@"进入了房间" titleColor:[ThemeColor messageDefaultTextColor] font:kRoomMessageDefalutFont];
|
||||
[attribute appendAttributedString:nickAttribute];
|
||||
[attribute appendAttributedString:enterRoomAttribute];
|
||||
|
||||
return attribute;
|
||||
nick = nick.length > 0 ? nick : @"";
|
||||
NSMutableAttributedString * attribute = [[NSMutableAttributedString alloc] init];
|
||||
NSMutableAttributedString * nickAttribute = [self createTextAttribute:nick titleColor:[ThemeColor messageNickColor] font:kRoomMessageDefalutFont];
|
||||
NSMutableAttributedString * enterRoomAttribute = [self createTextAttribute:@"进入了房间" titleColor:[ThemeColor messageDefaultTextColor] font:kRoomMessageDefalutFont];
|
||||
[attribute appendAttributedString:nickAttribute];
|
||||
[attribute appendAttributedString:enterRoomAttribute];
|
||||
|
||||
return attribute;
|
||||
}
|
||||
|
||||
|
||||
#pragma mark - 富文本的工具类
|
||||
#pragma mark - 富文本的基础工具方法
|
||||
|
||||
/// 生成一个图片的富文本
|
||||
/// @param imageUrl 网络图片的地址
|
||||
/// @param size 网络图片的大小
|
||||
+ (NSMutableAttributedString *)createUrlImageAttribute:(NSString *)imageUrl size:(CGSize)size {
|
||||
NetImageView *genderImageView = [[NetImageView alloc]init];
|
||||
genderImageView.imgUrl = imageUrl;
|
||||
|
||||
genderImageView.bounds = CGRectMake(0, 0, 25, 16);
|
||||
genderImageView.layer.masksToBounds = YES;
|
||||
genderImageView.contentMode = UIViewContentModeScaleAspectFill;
|
||||
NSMutableAttributedString * genderString = [NSMutableAttributedString yy_attachmentStringWithContent:genderImageView contentMode:UIViewContentModeScaleAspectFit attachmentSize:CGSizeMake(genderImageView.frame.size.width, genderImageView.frame.size.height) alignToFont:[UIFont systemFontOfSize:15.0] alignment:YYTextVerticalAlignmentCenter];
|
||||
return genderString;
|
||||
NetImageView *imageView = [[NetImageView alloc]init];
|
||||
imageView.imageUrl = imageUrl;
|
||||
|
||||
UIImage* image = imageView.image;
|
||||
if (image) {
|
||||
CGFloat scale = image.size.width / image.size.height;
|
||||
imageView.bounds = CGRectMake(0, 0, 16 * scale, 16);
|
||||
} else {
|
||||
imageView.bounds = CGRectMake(0, 0, 16, 16);
|
||||
}
|
||||
imageView.layer.masksToBounds = YES;
|
||||
imageView.contentMode = UIViewContentModeScaleAspectFill;
|
||||
NSMutableAttributedString * genderString = [NSMutableAttributedString yy_attachmentStringWithContent:imageView contentMode:UIViewContentModeScaleAspectFit attachmentSize:CGSizeMake(imageView.frame.size.width, imageView.frame.size.height) alignToFont:[UIFont systemFontOfSize:15.0] alignment:YYTextVerticalAlignmentCenter];
|
||||
return genderString;
|
||||
}
|
||||
|
||||
/// 生成本地一个图片的富文本
|
||||
/// @param imageName 网络图片的地址
|
||||
/// @param size 网络图片的大小
|
||||
+ (NSMutableAttributedString *)createLocalImageAttribute:(NSString *)imageName size:(CGSize)size {
|
||||
UIImageView *genderImageView = [[UIImageView alloc]init];
|
||||
genderImageView.image = [UIImage imageNamed:imageName];
|
||||
CGFloat kscale = (CGFloat)genderImageView.image.size.width / (CGFloat)genderImageView.image.size.height;
|
||||
genderImageView.bounds = CGRectMake(0, 0, 16 * kscale, 16);
|
||||
NSMutableAttributedString * genderString = [NSMutableAttributedString yy_attachmentStringWithContent:genderImageView contentMode:UIViewContentModeScaleAspectFit attachmentSize:CGSizeMake(genderImageView.frame.size.width, genderImageView.frame.size.height) alignToFont:[UIFont systemFontOfSize:15.0] alignment:YYTextVerticalAlignmentCenter];
|
||||
return genderString;
|
||||
UIImageView *genderImageView = [[UIImageView alloc]init];
|
||||
genderImageView.image = [UIImage imageNamed:imageName];
|
||||
CGFloat kscale = (CGFloat)genderImageView.image.size.width / (CGFloat)genderImageView.image.size.height;
|
||||
genderImageView.bounds = CGRectMake(0, 0, 16 * kscale, 16);
|
||||
NSMutableAttributedString * genderString = [NSMutableAttributedString yy_attachmentStringWithContent:genderImageView contentMode:UIViewContentModeScaleAspectFit attachmentSize:CGSizeMake(genderImageView.frame.size.width, genderImageView.frame.size.height) alignToFont:[UIFont systemFontOfSize:15.0] alignment:YYTextVerticalAlignmentCenter];
|
||||
return genderString;
|
||||
}
|
||||
|
||||
/// 生成本地一个图片的富文本
|
||||
/// @param image 本地的图片
|
||||
/// @param size 本地图片的大小
|
||||
+ (NSMutableAttributedString *)createImageAttribute:(UIImage *)image size:(CGSize)size {
|
||||
UIImageView *genderImageView = [[UIImageView alloc]init];
|
||||
genderImageView.image = image;
|
||||
CGFloat kscale = (CGFloat)genderImageView.image.size.width / (CGFloat)genderImageView.image.size.height;
|
||||
genderImageView.bounds = CGRectMake(0, 0, 16 * kscale,16);
|
||||
NSMutableAttributedString * genderString = [NSMutableAttributedString yy_attachmentStringWithContent:genderImageView contentMode:UIViewContentModeScaleAspectFit attachmentSize:CGSizeMake(genderImageView.frame.size.width, genderImageView.frame.size.height) alignToFont:[UIFont systemFontOfSize:15.0] alignment:YYTextVerticalAlignmentCenter];
|
||||
return genderString;
|
||||
UIImageView *genderImageView = [[UIImageView alloc]init];
|
||||
genderImageView.image = image;
|
||||
CGFloat kscale = (CGFloat)genderImageView.image.size.width / (CGFloat)genderImageView.image.size.height;
|
||||
genderImageView.bounds = CGRectMake(0, 0, 16 * kscale,16);
|
||||
NSMutableAttributedString * genderString = [NSMutableAttributedString yy_attachmentStringWithContent:genderImageView contentMode:UIViewContentModeScaleAspectFit attachmentSize:CGSizeMake(genderImageView.frame.size.width, genderImageView.frame.size.height) alignToFont:[UIFont systemFontOfSize:15.0] alignment:YYTextVerticalAlignmentCenter];
|
||||
return genderString;
|
||||
}
|
||||
|
||||
/// 生成一个富文本
|
||||
@@ -116,104 +116,32 @@
|
||||
/// @param titleColor 文字的颜色
|
||||
/// @param font 文字的大小
|
||||
+ (NSMutableAttributedString *)createTextAttribute:(NSString *)text titleColor:(UIColor *)titleColor font:(CGFloat)font {
|
||||
NSMutableAttributedString *attribute = [[NSMutableAttributedString alloc] initWithString:text attributes:nil];
|
||||
attribute.yy_font = [UIFont systemFontOfSize:font];
|
||||
attribute.yy_color = titleColor;
|
||||
attribute.yy_paragraphStyle = [self paragraphStyle];
|
||||
return attribute;
|
||||
NSMutableAttributedString *attribute = [[NSMutableAttributedString alloc] initWithString:text attributes:nil];
|
||||
attribute.yy_font = [UIFont systemFontOfSize:font];
|
||||
attribute.yy_color = titleColor;
|
||||
attribute.yy_paragraphStyle = [self paragraphStyle];
|
||||
return attribute;
|
||||
}
|
||||
|
||||
/// 设置文本的样式 间隙 缩进 ...
|
||||
+ (NSMutableParagraphStyle *)paragraphStyle {
|
||||
NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init];
|
||||
paraStyle.lineSpacing = 4.0f;//行间距
|
||||
// 强制排版(从左到右)
|
||||
paraStyle.alignment = NSTextAlignmentLeft;
|
||||
paraStyle.baseWritingDirection = NSWritingDirectionLeftToRight;
|
||||
|
||||
return paraStyle;
|
||||
NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init];
|
||||
paraStyle.lineSpacing = 4.0f;//行间距
|
||||
// 强制排版(从左到右)
|
||||
paraStyle.alignment = NSTextAlignmentLeft;
|
||||
paraStyle.baseWritingDirection = NSWritingDirectionLeftToRight;
|
||||
|
||||
return paraStyle;
|
||||
}
|
||||
|
||||
|
||||
/// 占位的富文本
|
||||
/// @param width 需要的间隙
|
||||
+ (NSMutableAttributedString *)createSapceAttribute:(CGFloat)width {
|
||||
UIView *spaceView = [[UIView alloc]init];
|
||||
spaceView.backgroundColor = [UIColor clearColor];
|
||||
spaceView.bounds = CGRectMake(0, 0, width,10);
|
||||
NSMutableAttributedString * genderString = [NSMutableAttributedString yy_attachmentStringWithContent:spaceView contentMode:UIViewContentModeScaleAspectFit attachmentSize:CGSizeMake(spaceView.frame.size.width, spaceView.frame.size.height) alignToFont:[UIFont systemFontOfSize:15.0] alignment:YYTextVerticalAlignmentCenter];
|
||||
return genderString;
|
||||
UIView *spaceView = [[UIView alloc]init];
|
||||
spaceView.backgroundColor = [UIColor clearColor];
|
||||
spaceView.bounds = CGRectMake(0, 0, width,10);
|
||||
NSMutableAttributedString * genderString = [NSMutableAttributedString yy_attachmentStringWithContent:spaceView contentMode:UIViewContentModeScaleAspectFit attachmentSize:CGSizeMake(spaceView.frame.size.width, spaceView.frame.size.height) alignToFont:[UIFont systemFontOfSize:15.0] alignment:YYTextVerticalAlignmentCenter];
|
||||
return genderString;
|
||||
}
|
||||
|
||||
|
||||
#pragma mark - Private Method
|
||||
|
||||
+ (UIImage *)cacheImage:(NSString *)urlStr type:(ImageType)type {
|
||||
NSString * key = [self getCacheImageKey:urlStr type:type];
|
||||
// 缓存的图片(内存)
|
||||
UIImage *image = [[SDImageCache sharedImageCache] imageFromMemoryCacheForKey:key];
|
||||
|
||||
// 缓存的图片(硬盘)
|
||||
if (!image) {
|
||||
image = [[SDImageCache sharedImageCache] imageFromDiskCacheForKey:key];
|
||||
}
|
||||
return image;
|
||||
}
|
||||
|
||||
|
||||
+ (NSString *)getCacheImageKey:(NSString *)imageUrl type:(ImageType)type {
|
||||
NSMutableString *urlString = [NSMutableString stringWithString:imageUrl];
|
||||
NSString * configUrl;
|
||||
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;
|
||||
case ImageTypeUserInfoAlbum:
|
||||
{
|
||||
configUrl = kImageTypeUserInfoAlbum;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (configUrl) {
|
||||
if ([imageUrl containsString:@"?"]) {
|
||||
[urlString appendString:@"|"];
|
||||
}else{
|
||||
[urlString appendString:@"?"];
|
||||
}
|
||||
[urlString appendString:configUrl];
|
||||
}
|
||||
|
||||
NSString *encodedString = (NSString *)
|
||||
CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,
|
||||
(CFStringRef)urlString,
|
||||
NULL,
|
||||
(CFStringRef)@"|",
|
||||
kCFStringEncodingUTF8));
|
||||
|
||||
return encodedString;
|
||||
}
|
||||
@end
|
||||
|
@@ -58,7 +58,7 @@
|
||||
#pragma mark - Getters And Setters
|
||||
- (void)setDisplayModel:(XPRoomMessageDisplayModel *)displayModel {
|
||||
_displayModel = displayModel;
|
||||
[self.contentLabel loadAttributedText:displayModel.contentAttribute load:YES];
|
||||
self.contentLabel.attributedText = displayModel.contentAttribute;
|
||||
displayModel.didSelectItem = ^(NSString * _Nonnull uid) {
|
||||
/// TODO : 展示用户卡片
|
||||
NSLog(@"%@", uid);
|
||||
|
@@ -10,8 +10,8 @@
|
||||
#import <Masonry/Masonry.h>
|
||||
///View
|
||||
#import "MicroWaveView.h"
|
||||
#import "NetImageView.h"
|
||||
|
||||
#import "UIImageView+LoadImage.h"
|
||||
#import "ThemeColor+Room.h"
|
||||
|
||||
#import "MicroQueueModel.h"
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
@interface MicroView ()<CAAnimationDelegate>
|
||||
///头像
|
||||
@property (nonatomic,strong) UIImageView *avatarImageView;
|
||||
@property (nonatomic,strong) NetImageView *avatarImageView;
|
||||
///坑位是否闭麦的
|
||||
@property (nonatomic,strong) UIImageView *micStateImageView;
|
||||
///昵称容器
|
||||
@@ -108,7 +108,7 @@
|
||||
- (void)configUser:(UserInfoModel *)userInfo {
|
||||
self.nickLabel.text = @"号坑位";
|
||||
if (userInfo) {
|
||||
[self.avatarImageView load_imageWithUrl:userInfo.avatar placeholderImage:[UIImageConstant defaultAvatarPlaceholder]];
|
||||
self.avatarImageView.imageUrl = userInfo.avatar;
|
||||
if (userInfo.gender == GenderType_Male) {
|
||||
[self.postionLabel setBackgroundColor:[ThemeColor positionMaleNickBackColor]];
|
||||
} else if(userInfo.gender == GenderType_Female){
|
||||
@@ -123,9 +123,9 @@
|
||||
}
|
||||
|
||||
#pragma mark - Getters And Setters
|
||||
- (UIImageView *)avatarImageView {
|
||||
- (NetImageView *)avatarImageView {
|
||||
if (!_avatarImageView) {
|
||||
_avatarImageView = [[UIImageView alloc] init];
|
||||
_avatarImageView = [[NetImageView alloc] init];
|
||||
_avatarImageView.userInteractionEnabled = YES;
|
||||
_avatarImageView.image = [UIImage imageNamed:@"room_position_normal"];
|
||||
}
|
||||
|
Reference in New Issue
Block a user