├── CDDGroupAvatarSwift.gif ├── Demo └── CDDGroupAvatarSwift │ ├── CDDGroupAvatarSwift │ ├── CDDGroupAvatarSwift-Bridging-Header.h │ ├── Assets.xcassets │ │ ├── Contents.json │ │ ├── man.imageset │ │ │ ├── man@2x.png │ │ │ ├── man@3x.png │ │ │ └── Contents.json │ │ ├── place.imageset │ │ │ ├── place@2x.png │ │ │ └── Contents.json │ │ ├── woman.imageset │ │ │ ├── woman@2x.png │ │ │ ├── woman@3x.png │ │ │ └── Contents.json │ │ ├── noCache1.imageset │ │ │ ├── noCache1.png │ │ │ └── Contents.json │ │ ├── noCache2.imageset │ │ │ ├── noCache2.png │ │ │ └── Contents.json │ │ ├── noCache3.imageset │ │ │ ├── noCache3.png │ │ │ └── Contents.json │ │ ├── noCache4.imageset │ │ │ ├── noCache4.png │ │ │ └── Contents.json │ │ ├── avatarholder.imageset │ │ │ ├── avatarholder.png │ │ │ └── Contents.json │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ ├── PFS │ │ └── KMCGeigerCounter │ │ │ ├── KMCGeigerCounterTick.aiff │ │ │ ├── KMCGeigerCounter.h │ │ │ └── KMCGeigerCounter.m │ ├── Base.lproj │ │ ├── LaunchScreen.storyboard │ │ └── Main.storyboard │ ├── Info.plist │ ├── AppDelegate.swift │ ├── TestViewController.swift │ └── ViewController.swift │ ├── Podfile │ └── CDDGroupAvatarSwift.xcodeproj │ └── project.pbxproj ├── CDDGroupAvatarSwift.podspec ├── CDDGroupAvatarSwift ├── NoCacheGroupAvatar │ ├── UIImageView+NoCacheGroup.swift │ ├── NoCacheAvatarManager.swift │ ├── UIButton+NoCacheGroup.swift │ └── UIImage+NoCacheGroup.swift ├── CacheGroupAvatar │ ├── UIImageView+Group.swift │ ├── AvatarManager.swift │ ├── UIButton+Group.swift │ ├── CacheAvatarHelper.swift │ └── UIImage+Group.swift └── Avatar │ ├── AvatarConfig.swift │ └── AvatarHelper.swift ├── README.md ├── .gitignore └── LICENSE /CDDGroupAvatarSwift.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RocketsChen/CDDGroupAvatarSwift/HEAD/CDDGroupAvatarSwift.gif -------------------------------------------------------------------------------- /Demo/CDDGroupAvatarSwift/CDDGroupAvatarSwift/CDDGroupAvatarSwift-Bridging-Header.h: -------------------------------------------------------------------------------- 1 | 2 | #import "KMCGeigerCounter.h" 3 | -------------------------------------------------------------------------------- /Demo/CDDGroupAvatarSwift/CDDGroupAvatarSwift/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /Demo/CDDGroupAvatarSwift/Podfile: -------------------------------------------------------------------------------- 1 | # Uncomment the next line to define a global platform for your project 2 | # platform :ios, '9.0' 3 | 4 | target 'CDDGroupAvatarSwift' do 5 | 6 | pod 'Kingfisher' 7 | 8 | end 9 | -------------------------------------------------------------------------------- /Demo/CDDGroupAvatarSwift/CDDGroupAvatarSwift/Assets.xcassets/man.imageset/man@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RocketsChen/CDDGroupAvatarSwift/HEAD/Demo/CDDGroupAvatarSwift/CDDGroupAvatarSwift/Assets.xcassets/man.imageset/man@2x.png -------------------------------------------------------------------------------- /Demo/CDDGroupAvatarSwift/CDDGroupAvatarSwift/Assets.xcassets/man.imageset/man@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RocketsChen/CDDGroupAvatarSwift/HEAD/Demo/CDDGroupAvatarSwift/CDDGroupAvatarSwift/Assets.xcassets/man.imageset/man@3x.png -------------------------------------------------------------------------------- /Demo/CDDGroupAvatarSwift/CDDGroupAvatarSwift/Assets.xcassets/place.imageset/place@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RocketsChen/CDDGroupAvatarSwift/HEAD/Demo/CDDGroupAvatarSwift/CDDGroupAvatarSwift/Assets.xcassets/place.imageset/place@2x.png -------------------------------------------------------------------------------- /Demo/CDDGroupAvatarSwift/CDDGroupAvatarSwift/Assets.xcassets/woman.imageset/woman@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RocketsChen/CDDGroupAvatarSwift/HEAD/Demo/CDDGroupAvatarSwift/CDDGroupAvatarSwift/Assets.xcassets/woman.imageset/woman@2x.png -------------------------------------------------------------------------------- /Demo/CDDGroupAvatarSwift/CDDGroupAvatarSwift/Assets.xcassets/woman.imageset/woman@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RocketsChen/CDDGroupAvatarSwift/HEAD/Demo/CDDGroupAvatarSwift/CDDGroupAvatarSwift/Assets.xcassets/woman.imageset/woman@3x.png -------------------------------------------------------------------------------- /Demo/CDDGroupAvatarSwift/CDDGroupAvatarSwift/Assets.xcassets/noCache1.imageset/noCache1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RocketsChen/CDDGroupAvatarSwift/HEAD/Demo/CDDGroupAvatarSwift/CDDGroupAvatarSwift/Assets.xcassets/noCache1.imageset/noCache1.png -------------------------------------------------------------------------------- /Demo/CDDGroupAvatarSwift/CDDGroupAvatarSwift/Assets.xcassets/noCache2.imageset/noCache2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RocketsChen/CDDGroupAvatarSwift/HEAD/Demo/CDDGroupAvatarSwift/CDDGroupAvatarSwift/Assets.xcassets/noCache2.imageset/noCache2.png -------------------------------------------------------------------------------- /Demo/CDDGroupAvatarSwift/CDDGroupAvatarSwift/Assets.xcassets/noCache3.imageset/noCache3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RocketsChen/CDDGroupAvatarSwift/HEAD/Demo/CDDGroupAvatarSwift/CDDGroupAvatarSwift/Assets.xcassets/noCache3.imageset/noCache3.png -------------------------------------------------------------------------------- /Demo/CDDGroupAvatarSwift/CDDGroupAvatarSwift/Assets.xcassets/noCache4.imageset/noCache4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RocketsChen/CDDGroupAvatarSwift/HEAD/Demo/CDDGroupAvatarSwift/CDDGroupAvatarSwift/Assets.xcassets/noCache4.imageset/noCache4.png -------------------------------------------------------------------------------- /Demo/CDDGroupAvatarSwift/CDDGroupAvatarSwift/PFS/KMCGeigerCounter/KMCGeigerCounterTick.aiff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RocketsChen/CDDGroupAvatarSwift/HEAD/Demo/CDDGroupAvatarSwift/CDDGroupAvatarSwift/PFS/KMCGeigerCounter/KMCGeigerCounterTick.aiff -------------------------------------------------------------------------------- /Demo/CDDGroupAvatarSwift/CDDGroupAvatarSwift/Assets.xcassets/avatarholder.imageset/avatarholder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RocketsChen/CDDGroupAvatarSwift/HEAD/Demo/CDDGroupAvatarSwift/CDDGroupAvatarSwift/Assets.xcassets/avatarholder.imageset/avatarholder.png -------------------------------------------------------------------------------- /Demo/CDDGroupAvatarSwift/CDDGroupAvatarSwift/Assets.xcassets/noCache1.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "filename" : "noCache1.png", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /Demo/CDDGroupAvatarSwift/CDDGroupAvatarSwift/Assets.xcassets/noCache2.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "filename" : "noCache2.png", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /Demo/CDDGroupAvatarSwift/CDDGroupAvatarSwift/Assets.xcassets/noCache3.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "filename" : "noCache3.png", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /Demo/CDDGroupAvatarSwift/CDDGroupAvatarSwift/Assets.xcassets/noCache4.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "filename" : "noCache4.png", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /Demo/CDDGroupAvatarSwift/CDDGroupAvatarSwift/Assets.xcassets/place.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "filename" : "place@2x.png", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /Demo/CDDGroupAvatarSwift/CDDGroupAvatarSwift/Assets.xcassets/avatarholder.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "filename" : "avatarholder.png", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /Demo/CDDGroupAvatarSwift/CDDGroupAvatarSwift/Assets.xcassets/man.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "filename" : "man@2x.png", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "filename" : "man@3x.png", 15 | "scale" : "3x" 16 | } 17 | ], 18 | "info" : { 19 | "version" : 1, 20 | "author" : "xcode" 21 | } 22 | } -------------------------------------------------------------------------------- /Demo/CDDGroupAvatarSwift/CDDGroupAvatarSwift/Assets.xcassets/woman.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "filename" : "woman@2x.png", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "filename" : "woman@3x.png", 15 | "scale" : "3x" 16 | } 17 | ], 18 | "info" : { 19 | "version" : 1, 20 | "author" : "xcode" 21 | } 22 | } -------------------------------------------------------------------------------- /Demo/CDDGroupAvatarSwift/CDDGroupAvatarSwift/PFS/KMCGeigerCounter/KMCGeigerCounter.h: -------------------------------------------------------------------------------- 1 | // 2 | // KMCGeigerCounter.h 3 | // KMCGeigerCounter 4 | // 5 | // Created by Kevin Conner on 10/21/14. 6 | // Copyright (c) 2014 Kevin Conner. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | typedef NS_ENUM(NSUInteger, KMCGeigerCounterPosition) { 12 | KMCGeigerCounterPositionLeft, 13 | KMCGeigerCounterPositionMiddle, 14 | KMCGeigerCounterPositionRight 15 | }; 16 | 17 | @interface KMCGeigerCounter : NSObject 18 | 19 | // Set [KMCGeigerCounter sharedGeigerCounter].enabled = YES from -application:didFinishLaunchingWithOptions:. 20 | @property (nonatomic, assign, getter = isEnabled) BOOL enabled; 21 | 22 | // The meter draws over the status bar. Set the window level manually if your own custom windows obscure it. 23 | @property (nonatomic, assign) UIWindowLevel windowLevel; 24 | 25 | // Position of the meter in the status bar. Takes effect on next enable. 26 | @property (nonatomic, assign) KMCGeigerCounterPosition position; 27 | 28 | @property (nonatomic, readonly, getter = isRunning) BOOL running; 29 | @property (nonatomic, readonly) NSInteger droppedFrameCountInLastSecond; 30 | @property (nonatomic, readonly) NSInteger drawnFrameCountInLastSecond; // -1 until one second of frames have been collected 31 | 32 | + (instancetype)sharedGeigerCounter; 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /CDDGroupAvatarSwift.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = 'CDDGroupAvatarSwift' 3 | s.version = '1.2.5' 4 | s.summary = 'iOS 群头像 / Easy to use' 5 | 6 | s.description = <<-DESC 7 | iOS 群头像功能,像加载一张图片那么简单。 8 | DESC 9 | 10 | s.homepage = 'https://github.com/RocketsChen/CDDGroupAvatarSwift' 11 | s.license = 'MIT' #开源协议 12 | s.authors = {'RcoketsChen' => '1062749739@qq.com'} 13 | s.platform = :ios, '9.0' 14 | s.source = {:git => 'https://github.com/RocketsChen/CDDGroupAvatarSwift.git', :tag => s.version} 15 | s.requires_arc = true 16 | s.frameworks = 'UIKit', 'Foundation' 17 | s.default_subspec = 'Cache' 18 | 19 | s.subspec 'NoCache' do |ss| 20 | 21 | ss.source_files = 'CDDGroupAvatarSwift/Avatar/*.swift' , 'CDDGroupAvatarSwift/NoCacheGroupAvatar/*.swift' 22 | 23 | end 24 | 25 | 26 | s.subspec 'Cache' do |ss| 27 | 28 | ss.source_files = 'CDDGroupAvatarSwift/Avatar/*.swift' , 'CDDGroupAvatarSwift/CacheGroupAvatar/*.swift' 29 | s.dependency 'Kingfisher' 30 | 31 | end 32 | 33 | 34 | s.subspec 'Core' do |ss| 35 | 36 | ss.source_files = 'CDDGroupAvatarSwift/Avatar/*.swift' , 'CDDGroupAvatarSwift/NoCacheGroupAvatar/*.swift' , 'CDDGroupAvatarSwift/CacheGroupAvatar/*.swift' 37 | s.dependency 'Kingfisher' 38 | 39 | end 40 | 41 | end 42 | 43 | -------------------------------------------------------------------------------- /CDDGroupAvatarSwift/NoCacheGroupAvatar/UIImageView+NoCacheGroup.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UIImageView+NoCacheGroup.swift 3 | // CDDGroupAvatarSwift 4 | // 5 | // Created by 陈甸甸 on 2020/3/11. 6 | // Copyright © 2020 RocketsChen. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | extension UIImageView { 12 | 13 | /// 设置群头像 14 | /// - Parameters: 15 | /// - groupId: 群头像id 16 | /// - groupSource: 群头像数据源数组 17 | /// - setImageHandler: 绘制好的群头像图片 18 | /// - groupImageHandler: (_ groupId: String, _ groupImage: UIImage, _ itemImageArray: [UIImage], _ cacheId: String) 19 | public func setNoCacheImageAvatar(groupId: String, groupSource: [UIImage], setImageHandler: GroupSetImageHandler? = nil, groupImageHandler: GroupImageHandler? = nil) { 20 | 21 | UIImage.setImageAvatar(groupId, groupSource, CGSize(width: self.frame.size.width, height: self.frame.size.height), {[weak self] (groupImage) in 22 | guard let self = self else { return } 23 | self.image = groupImage 24 | if setImageHandler != nil { 25 | setImageHandler!(groupImage) 26 | } 27 | }) {[weak self] (groupId, groupImage, itemImageArray, cacheId) in 28 | guard let self = self else { return } 29 | self.image = groupImage 30 | if groupImageHandler != nil { 31 | groupImageHandler!(groupId, groupImage, itemImageArray, cacheId) 32 | } 33 | } 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /CDDGroupAvatarSwift/NoCacheGroupAvatar/NoCacheAvatarManager.swift: -------------------------------------------------------------------------------- 1 | // 2 | // NoCacheAvatarManager.swift 3 | // CDDGroupAvatarSwift 4 | // 5 | // Created by 陈甸甸 on 2020/3/11. 6 | // Copyright © 2020 RocketsChen. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | public struct NoCacheAvatarManager { 12 | 13 | /// 头像类型枚举(默认微信样式) 14 | public static var groupAvatarType: DCGroupAvatarType = .WeChat 15 | 16 | /// 微博外边圈宽度(默认:10) 17 | public static var bordWidth: CGFloat = AvatarConfig.DCWeiBoAvatarbordWidth 18 | 19 | /// 微信和QQ群内小头像间距(默认值:2) 20 | public static var distanceBetweenAvatar: CGFloat = AvatarConfig.DCDistanceBetweenAvatar 21 | 22 | /// 头像背景(默认微信背景色) 23 | public static var avatarBgColor: UIColor = UIColor.bgColor 24 | 25 | } 26 | 27 | 28 | // MARK: - 方法扩展 29 | extension AvatarConfig { 30 | 31 | public static func noCacheIdMD5(_ groupId: String , _ groupSource: [UIImage]) -> String { 32 | return idMD5(groupId, groupSource) 33 | } 34 | 35 | 36 | // MARK: - 私有方法 37 | private static func idMD5(_ groupId: String , _ groupSource: [Any]) -> String { 38 | 39 | if groupSource.count == 0 { 40 | return "" 41 | } 42 | 43 | let appStrs = "id\(groupId)_num\(groupSource.count)_lastObj\(groupSource.last!)_distance\(NoCacheAvatarManager.distanceBetweenAvatar)_bordWidth\(NoCacheAvatarManager.avatarBgColor)_bgColor\(NoCacheAvatarManager.avatarBgColor)" 44 | return appStrs.md5 ?? "" 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /CDDGroupAvatarSwift/CacheGroupAvatar/UIImageView+Group.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UIImageView+Group.swift 3 | // CDDGroupAvatarSwift 4 | // 5 | // Created by 陈甸甸 on 2020/3/11. 6 | // Copyright © 2020 RocketsChen. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import Kingfisher 11 | 12 | extension UIImageView { 13 | 14 | /// 设置群头像 15 | /// - Parameters: 16 | /// - groupId: 群头像id 17 | /// - groupSource: 群头像数据源数组 18 | /// - itemPlaceholder: 占位图 例:[image1,image2] 权重大于 placeholderImage属性 19 | /// - options: 加载图片选项,详情可见DCGroupAvatarCacheType枚举 20 | /// - setImageHandler: 绘制好的群头像图片 21 | /// - groupImageHandler: _ groupId: String, _ groupImage: UIImage, _ itemImageArray: [UIImage], _ cacheId: String 22 | public func setImageAvatar(groupId: String, groupSource: [String], itemPlaceholder: [UIImage]? = nil, options: DCGroupAvatarCacheType? = .Default, setImageHandler: GroupSetImageHandler? = nil, groupImageHandler: GroupImageHandler? = nil) { 23 | 24 | UIImage.setCacheImageAvatar(groupId, groupSource, itemPlaceholder, CGSize(width: self.frame.size.width, height: self.frame.size.height), options, {[weak self] (groupImage) in 25 | guard let self = self else { return } 26 | self.image = groupImage 27 | if setImageHandler != nil { 28 | setImageHandler!(groupImage) 29 | } 30 | }) {[weak self] (groupId, groupImage, itemImageArray, cacheId) in 31 | guard let self = self else { return } 32 | self.image = groupImage 33 | if groupImageHandler != nil { 34 | groupImageHandler!(groupId, groupImage, itemImageArray, cacheId) 35 | } 36 | } 37 | } 38 | } 39 | 40 | -------------------------------------------------------------------------------- /Demo/CDDGroupAvatarSwift/CDDGroupAvatarSwift/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Demo/CDDGroupAvatarSwift/CDDGroupAvatarSwift/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | $(PRODUCT_BUNDLE_PACKAGE_TYPE) 17 | CFBundleShortVersionString 18 | $(MARKETING_VERSION) 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | NSAppTransportSecurity 24 | 25 | NSAllowsArbitraryLoads 26 | 27 | 28 | UILaunchStoryboardName 29 | LaunchScreen 30 | UIMainStoryboardFile 31 | Main 32 | UIRequiredDeviceCapabilities 33 | 34 | armv7 35 | 36 | UISupportedInterfaceOrientations 37 | 38 | UIInterfaceOrientationPortrait 39 | UIInterfaceOrientationLandscapeLeft 40 | UIInterfaceOrientationLandscapeRight 41 | 42 | UISupportedInterfaceOrientations~ipad 43 | 44 | UIInterfaceOrientationPortrait 45 | UIInterfaceOrientationPortraitUpsideDown 46 | UIInterfaceOrientationLandscapeLeft 47 | UIInterfaceOrientationLandscapeRight 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CDDGroupAvatarSwift 2 | 3 | #### 这框架的初衷是想使群头像的实现尽可能的能像加载一张图片那么简单 4 | 5 | ![GIF](https://github.com/RocketsChen/CDDGroupAvatarSwift/blob/master/CDDGroupAvatarSwift.gif) 6 | 7 | #### OC版本: 8 | 9 | [OC版本传送门](https://github.com/RocketsChen/CDDGroupAvatar) 10 | 11 | #### 安装: 12 | 13 | * CocoaPods 14 | 15 | 1:在 Podfile 中添加 pod '`CDDGroupAvatarSwift`',执行 pod install 或 pod update。 16 | 17 | * 如果只需要无缓存版本:pod '`CDDGroupAvatarSwift/NoCache`,更多详情可以查看podspec文件 18 | 19 | 20 | 21 | * 手动导入 22 | 23 | 1:将demo项目中的 `CDDGroupAvatarSwift` 文件夹所有内容拖入你的工程中。 24 | 2:集成 Kingfisher 框架。 25 | 26 | * 用法 27 | 28 | 1:导入`import CDDGroupAvatarSwift`可以拥有全部功能。 29 | 2:调用对应控件的类方法。 30 | 3:如果有使用上的疑问,可以下载演示demo进行查看。 31 | 32 | #### 代码: 33 | 34 | ##### 缓存版本: 默认依赖`Kingfisher` 35 | 36 | ``` 37 | // UIImageView 38 | avImageViewW3.setImageAvatar(groupId: "avImageViewW3", groupSource: groupNum3) 39 | 40 | // UIButton 41 | // Image 42 | avaBgButton.setImageAvatar(groupId: "avaBgButtonImage", groupSource: groupNum9, state: .normal) 43 | // Background 44 | avaBgButton.setBackgroundAvatar(groupId: "avaBgButtonBgImage", groupSource: groupNum9, state: .normal) 45 | ``` 46 | 47 | ##### 纯UI版本: 48 | 49 | ``` 50 | // UIImageView 51 | ncImageViewW1.setNoCacheImageAvatar(groupId: "ncImageViewW1", groupSource: [UIImage(named: "noCache1")!]) 52 | 53 | // UIButton 54 | // Image 55 | avaBgButton.setNoCacheImageAvatar(groupId: "avaBgButtonImage", groupSource: [UIImage(named: "noCache1")!], state: .normal) 56 | // Background 57 | avaBgButton.setNoCacheBackgroundAvatar(groupId: "avaBgButtonBgImage", groupSource: [UIImage(named: "noCache1")!], state: .normal) 58 | ``` 59 | 60 | ## 版本更新 61 | 62 | | version | note | 63 | | ------ | ------ | 64 | | 1.1.0 | 初步完成基本需求| 65 | 66 | 67 | 68 | #### 关于版本: 69 | 70 | 目前`iOS`和`Swift`版本均已开源,后续会继续优化完善~ 71 | 72 | 欢迎 Star✨ 73 | 74 | 75 | #### Agreement 76 | 77 | * ` CDDGroupAvatarSwift` licensed under the MIT license is used. Refer to [LICENSE](https://opensource.org/licenses/MIT) for more information. 78 | 79 | 80 | -------------------------------------------------------------------------------- /CDDGroupAvatarSwift/CacheGroupAvatar/AvatarManager.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AvatarManager.swift 3 | // CDDGroupAvatarSwift 4 | // 5 | // Created by 陈甸甸 on 2020/3/9. 6 | // Copyright © 2020 RocketsChen. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | public struct AvatarManager { 12 | 13 | 14 | /// 请求的baseURL。这应该只包含URL的共体部分,例如'http://www.example.com'。 15 | public static var baseUrl: String? 16 | 17 | /// 一次性设置小头像加载失败的占位图 : 权重低于类方法中的placeholder属性 placeholderImage < (id)placeholder 18 | public static var placeholderImage: UIImage = UIImage() 19 | 20 | /// 头像类型枚举(默认微信样式) 21 | public static var groupAvatarType: DCGroupAvatarType = .WeChat 22 | 23 | /// 微博外边圈宽度(默认:10) 24 | public static var bordWidth: CGFloat = AvatarConfig.DCWeiBoAvatarbordWidth 25 | 26 | /// 微信和QQ群内小头像间距(默认值:2) 27 | public static var distanceBetweenAvatar: CGFloat = AvatarConfig.DCDistanceBetweenAvatar 28 | 29 | /// 头像背景(默认微信背景色) 30 | public static var avatarBgColor: UIColor = UIColor.bgColor 31 | 32 | } 33 | 34 | 35 | 36 | // MARK: - 方法扩展 37 | extension AvatarConfig { 38 | 39 | public static func urlStr(_ avaStr: String) -> String { 40 | 41 | guard let baseUrl = AvatarManager.baseUrl else { 42 | return avaStr 43 | } 44 | 45 | return avaStr.contains("www.") ? avaStr : "\(baseUrl)\(avaStr)" 46 | } 47 | 48 | 49 | public static func cacheIdMD5(_ groupId: String , _ groupSource: [String]) -> String { 50 | idMD5(groupId, groupSource) 51 | } 52 | 53 | 54 | // MARK: - 私有方法 55 | private static func idMD5(_ groupId: String , _ groupSource: [Any]) -> String { 56 | 57 | if groupSource.count == 0 { 58 | return "" 59 | } 60 | 61 | let appStrs = "id\(groupId)_num\(groupSource.count)_lastObj\(groupSource.last!)_distance\(AvatarManager.distanceBetweenAvatar)_bordWidth\(AvatarManager.avatarBgColor)_bgColor\(AvatarManager.avatarBgColor)" 62 | return appStrs.md5 ?? "" 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /Demo/CDDGroupAvatarSwift/CDDGroupAvatarSwift/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "20x20", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "20x20", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "29x29", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "29x29", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "40x40", 66 | "scale" : "1x" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "size" : "40x40", 71 | "scale" : "2x" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "size" : "76x76", 76 | "scale" : "1x" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "size" : "76x76", 81 | "scale" : "2x" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "size" : "83.5x83.5", 86 | "scale" : "2x" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "size" : "1024x1024", 91 | "scale" : "1x" 92 | } 93 | ], 94 | "info" : { 95 | "version" : 1, 96 | "author" : "xcode" 97 | } 98 | } -------------------------------------------------------------------------------- /Demo/CDDGroupAvatarSwift/CDDGroupAvatarSwift/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // CDDGroupAvatarSwift 4 | // 5 | // Created by 陈甸甸 on 2020/3/8. 6 | // Copyright © 2020 RocketsChen. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | 12 | @UIApplicationMain 13 | class AppDelegate: UIResponder, UIApplicationDelegate { 14 | 15 | var window: UIWindow? 16 | 17 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 18 | 19 | #if DEBUG 20 | 21 | KMCGeigerCounter.shared()?.position = .middle 22 | KMCGeigerCounter.shared()?.isEnabled = true 23 | 24 | #endif 25 | 26 | return true 27 | } 28 | 29 | func applicationWillResignActive(_ application: UIApplication) { 30 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 31 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 32 | } 33 | 34 | func applicationDidEnterBackground(_ application: UIApplication) { 35 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 36 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 37 | } 38 | 39 | func applicationWillEnterForeground(_ application: UIApplication) { 40 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 41 | } 42 | 43 | func applicationDidBecomeActive(_ application: UIApplication) { 44 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 45 | } 46 | 47 | func applicationWillTerminate(_ application: UIApplication) { 48 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 49 | } 50 | } 51 | 52 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## User settings 6 | xcuserdata/ 7 | 8 | ## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9) 9 | *.xcscmblueprint 10 | *.xccheckout 11 | 12 | ## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4) 13 | build/ 14 | DerivedData/ 15 | *.moved-aside 16 | *.pbxuser 17 | !default.pbxuser 18 | *.mode1v3 19 | !default.mode1v3 20 | *.mode2v3 21 | !default.mode2v3 22 | *.perspectivev3 23 | !default.perspectivev3 24 | 25 | ## Obj-C/Swift specific 26 | *.hmap 27 | 28 | ## App packaging 29 | *.ipa 30 | *.dSYM.zip 31 | *.dSYM 32 | 33 | ## Playgrounds 34 | timeline.xctimeline 35 | playground.xcworkspace 36 | 37 | # Swift Package Manager 38 | # 39 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 40 | # Packages/ 41 | # Package.pins 42 | # Package.resolved 43 | # *.xcodeproj 44 | # 45 | # Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata 46 | # hence it is not needed unless you have added a package configuration file to your project 47 | # .swiftpm 48 | 49 | .build/ 50 | 51 | # CocoaPods 52 | # 53 | # We recommend against adding the Pods directory to your .gitignore. However 54 | # you should judge for yourself, the pros and cons are mentioned at: 55 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 56 | # 57 | # Pods/ 58 | # 59 | # Add this line if you want to avoid checking in source code from the Xcode workspace 60 | # *.xcworkspace 61 | 62 | # Carthage 63 | # 64 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 65 | # Carthage/Checkouts 66 | 67 | Carthage/Build/ 68 | 69 | # Accio dependency management 70 | Dependencies/ 71 | .accio/ 72 | 73 | # fastlane 74 | # 75 | # It is recommended to not store the screenshots in the git repo. 76 | # Instead, use fastlane to re-generate the screenshots whenever they are needed. 77 | # For more information about the recommended setup visit: 78 | # https://docs.fastlane.tools/best-practices/source-control/#source-control 79 | 80 | fastlane/report.xml 81 | fastlane/Preview.html 82 | fastlane/screenshots/**/*.png 83 | fastlane/test_output 84 | 85 | # Code Injection 86 | # 87 | # After new code Injection tools there's a generated folder /iOSInjectionProject 88 | # https://github.com/johnno1962/injectionforxcode 89 | 90 | iOSInjectionProject/ 91 | -------------------------------------------------------------------------------- /CDDGroupAvatarSwift/NoCacheGroupAvatar/UIButton+NoCacheGroup.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UIButton+NoCacheGroup.swift 3 | // CDDGroupAvatarSwift 4 | // 5 | // Created by 陈甸甸 on 2020/3/11. 6 | // Copyright © 2020 RocketsChen. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | extension UIButton { 12 | 13 | /// 设置群头像【Image】 14 | /// - Parameters: 15 | /// - groupId: 群头像id 16 | /// - groupSource: 群头像数据源数组 17 | /// - state: 状态 18 | /// - setImageHandler: 绘制好的群头像图片 19 | /// - groupImageHandler: (_ groupId: String, _ groupImage: UIImage, _ itemImageArray: [UIImage], _ cacheId: String) 20 | public func setNoCacheImageAvatar(groupId: String, groupSource: [UIImage], state: UIControl.State, setImageHandler: GroupSetImageHandler? = nil, groupImageHandler: GroupImageHandler? = nil) { 21 | 22 | UIImage.setImageAvatar(groupId, groupSource, CGSize(width: self.frame.size.width, height: self.frame.size.height), {[weak self] (groupImage) in 23 | guard let self = self else { return } 24 | self.setImage(groupImage, for: state) 25 | if setImageHandler != nil { 26 | setImageHandler!(groupImage) 27 | } 28 | }) {[weak self] (groupId, groupImage, itemImageArray, cacheId) in 29 | guard let self = self else { return } 30 | self.setImage(groupImage, for: state) 31 | if groupImageHandler != nil { 32 | groupImageHandler!(groupId, groupImage, itemImageArray, cacheId) 33 | } 34 | } 35 | 36 | } 37 | 38 | /// 设置群头像【BackgroundImage】 39 | /// - Parameters: 40 | /// - groupId: 群头像id 41 | /// - groupSource: 群头像数据源数组 42 | /// - state: 状态 43 | /// - setImageHandler: 绘制好的群头像图片 44 | /// - groupImageHandler: (_ groupId: String, _ groupImage: UIImage, _ itemImageArray: [UIImage], _ cacheId: String) 45 | public func setNoCacheBackgroundAvatar(groupId: String, groupSource: [UIImage], state: UIControl.State, setImageHandler: GroupSetImageHandler? = nil, groupImageHandler: GroupImageHandler? = nil) { 46 | 47 | UIImage.setImageAvatar(groupId, groupSource, CGSize(width: self.frame.size.width, height: self.frame.size.height), {[weak self] (groupImage) in 48 | guard let self = self else { return } 49 | self.setBackgroundImage(groupImage, for: state) 50 | if setImageHandler != nil { 51 | setImageHandler!(groupImage) 52 | } 53 | }) {[weak self] (groupId, groupImage, itemImageArray, cacheId) in 54 | guard let self = self else { return } 55 | self.setBackgroundImage(groupImage, for: state) 56 | if groupImageHandler != nil { 57 | groupImageHandler!(groupId, groupImage, itemImageArray, cacheId) 58 | } 59 | } 60 | } 61 | } 62 | 63 | -------------------------------------------------------------------------------- /CDDGroupAvatarSwift/Avatar/AvatarConfig.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AvatarConfig.swift 3 | // CDDGroupAvatarSwift 4 | // 5 | // Created by 陈甸甸 on 2020/3/8. 6 | // Copyright © 2020 RocketsChen. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import Foundation 11 | 12 | 13 | public struct AvatarConfig { 14 | 15 | /// 常量方法 16 | static let DCMaxWeChatCount: Int = 9 17 | static let DCMaxQQCount: Int = 4 18 | static let DCMaxWeiBoCount: Int = 4 19 | 20 | static let DCMaxWeChatColumn: Int = 3 21 | 22 | static let DCDistanceBetweenAvatar: CGFloat = 2 23 | static let DCWeiBoAvatarbordWidth: CGFloat = 10 24 | 25 | } 26 | 27 | 28 | /// 头像类型枚举 29 | /// 30 | /// - Parameters: 31 | /// - WeChat: 微信 32 | /// - NewQQ: QQ(以中心点分割的半圆拼接) 33 | /// - OldQQ: WeiBo(圆拼接) 34 | public enum DCGroupAvatarType: Int { 35 | 36 | case WeChat 37 | case QQ 38 | case WeiBo 39 | } 40 | 41 | 42 | 43 | /// 加载图片枚举 * cache 44 | /// 45 | /// - Parameters: 46 | /// - SDCGroupAvatarDefaultCached: 默认:走缓存 取到返回 没有则获取最新 47 | /// - SDCGroupAvatarRefreshCached: 先读缓存再获取最新 48 | public enum DCGroupAvatarCacheType: Int { 49 | 50 | case Default 51 | case Refresh 52 | } 53 | 54 | /// 组内头像的数量 55 | /// 56 | /// - Parameters: 57 | /// - One: 1 58 | /// - Two: 2 59 | /// - Three: 3 60 | /// - Four: 4 (QQ最大值) / (微博最大值) 61 | /// - Five: 5 62 | /// - Six: 6 63 | /// - Seven: 7 64 | /// - Eight: 8 65 | /// - Nine: 9 (微信最大值) 66 | public enum DCNumberOfGroupAvatarType: Int { 67 | 68 | case One 69 | case Two 70 | case Three 71 | case Four 72 | case Five 73 | case Six 74 | case Seven 75 | case Eight 76 | case Nine 77 | 78 | 79 | public func description() -> Int { 80 | 81 | switch self { 82 | case .One: 83 | return 1 84 | case .Two: 85 | return 2 86 | case .Three: 87 | return 3 88 | case .Four: 89 | return 4 90 | case .Five: 91 | return 5 92 | case .Six: 93 | return 6 94 | case .Seven: 95 | return 7 96 | case .Eight: 97 | return 8 98 | case .Nine: 99 | return 9 100 | } 101 | } 102 | } 103 | 104 | 105 | 106 | // MARK: - Color扩展 107 | extension UIColor { 108 | 109 | public static var bgColor: UIColor { 110 | return .init(red: 238 / 255.0, green: 238 / 255.0, blue: 238 / 255.0, alpha: 1.0) 111 | } 112 | } 113 | 114 | 115 | public typealias GroupImageHandler = ((_ groupId: String, _ groupImage: UIImage, _ itemImageArray: [UIImage], _ cacheId: String) -> Void) 116 | 117 | public typealias GroupSetImageHandler = (_ setImage: UIImage) -> Void 118 | 119 | public typealias GroupImageParamsHandler = () -> Void 120 | 121 | public typealias FetchImageHandler = (_ unitImages: [UIImage], _ succeed: Bool) -> Void 122 | 123 | public typealias AsynFetchImageHandler = (_ unitImages: [UIImage]) -> Void 124 | 125 | public typealias FetchImageParamsHandler = () -> Void 126 | 127 | 128 | -------------------------------------------------------------------------------- /CDDGroupAvatarSwift/CacheGroupAvatar/UIButton+Group.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UIButton+Group.swift 3 | // CDDGroupAvatarSwift 4 | // 5 | // Created by 陈甸甸 on 2020/3/11. 6 | // Copyright © 2020 RocketsChen. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import Kingfisher 11 | 12 | extension UIButton { 13 | 14 | /// 设置群头像【Image】 15 | /// - Parameters: 16 | /// - groupId: 群头像id 17 | /// - groupSource: 群头像数据源数组 18 | /// - state: 状态 19 | /// - options: 加载图片选项,详情可见DCGroupAvatarCacheType枚举 20 | /// - setImageHandler: 绘制好的群头像图片 21 | /// - groupImageHandler: (_ groupId: String, _ groupImage: UIImage, _ itemImageArray: [UIImage], _ cacheId: String) 22 | public func setImageAvatar(groupId: String, groupSource: [String], itemPlaceholder: [UIImage]? = nil, state: UIControl.State, options: DCGroupAvatarCacheType? = .Default, setImageHandler: GroupSetImageHandler? = nil, groupImageHandler: GroupImageHandler? = nil) { 23 | 24 | UIImage.setCacheImageAvatar(groupId, groupSource, itemPlaceholder, CGSize(width: self.frame.size.width, height: self.frame.size.height), options, {[weak self] (groupImage) in 25 | guard let self = self else { return } 26 | self.setImage(groupImage, for: state) 27 | if setImageHandler != nil { 28 | setImageHandler!(groupImage) 29 | } 30 | }) {[weak self] (groupId, groupImage, itemImageArray, cacheId) in 31 | guard let self = self else { return } 32 | self.setImage(groupImage, for: state) 33 | if groupImageHandler != nil { 34 | groupImageHandler!(groupId, groupImage, itemImageArray, cacheId) 35 | } 36 | } 37 | 38 | } 39 | 40 | 41 | /// 设置群头像【BackgroundImage】 42 | /// - Parameters: 43 | /// - groupId: 群头像id 44 | /// - groupSource: 群头像数据源数组 45 | /// - state: 状态 46 | /// - options: 加载图片选项,详情可见DCGroupAvatarCacheType枚举 47 | /// - setImageHandler: 绘制好的群头像图片 48 | /// - groupImageHandler: (_ groupId: String, _ groupImage: UIImage, _ itemImageArray: [UIImage], _ cacheId: String) 49 | public func setBackgroundAvatar(groupId: String, groupSource: [String], itemPlaceholder: [UIImage]? = nil, state: UIControl.State, options: DCGroupAvatarCacheType? = .Default, setImageHandler: GroupSetImageHandler? = nil, groupImageHandler: GroupImageHandler? = nil) { 50 | 51 | UIImage.setCacheImageAvatar(groupId, groupSource, itemPlaceholder, CGSize(width: self.frame.size.width, height: self.frame.size.height), options, {[weak self] (groupImage) in 52 | guard let self = self else { return } 53 | self.setBackgroundImage(groupImage, for: state) 54 | if setImageHandler != nil { 55 | setImageHandler!(groupImage) 56 | } 57 | }) {[weak self] (groupId, groupImage, itemImageArray, cacheId) in 58 | guard let self = self else { return } 59 | self.setBackgroundImage(groupImage, for: state) 60 | if groupImageHandler != nil { 61 | groupImageHandler!(groupId, groupImage, itemImageArray, cacheId) 62 | } 63 | } 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /CDDGroupAvatarSwift/CacheGroupAvatar/CacheAvatarHelper.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CacheAvatarHelper.swift 3 | // CDDGroupAvatarSwift 4 | // 5 | // Created by 陈甸甸 on 2020/3/11. 6 | // Copyright © 2020 RocketsChen. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import Kingfisher 11 | 12 | 13 | public struct CacheAvatarHelper { 14 | 15 | 16 | // MARK: - 获取群头像内部小头像缓存数组 17 | public static func fetchItemCacheArraySource(_ groupSource: [String]) -> [UIImage] { 18 | 19 | var cacheArray = [UIImage]() 20 | for item in groupSource { 21 | 22 | if let itemIamge = ImageCache.default.retrieveImageInMemoryCache(forKey: AvatarConfig.urlStr(item)) { 23 | cacheArray.append(itemIamge) 24 | } 25 | } 26 | return cacheArray 27 | 28 | } 29 | 30 | 31 | // MARK: - 批量加载地址头像 32 | public static func fetchLoadImageSource(groupSource: [String], cacheGroupImage: UIImage? = nil, itemPlaceholder: [UIImage]? = nil, completedHandler: FetchImageHandler? = nil) { 33 | 34 | var groupImages = Array(repeating: UIImage(), count: groupSource.count) 35 | var succeed: Bool = false 36 | 37 | var groupSum: Int = 0 38 | var placeholderSum: Int = 0 39 | 40 | let callCompletedBlock: GroupImageParamsHandler = { 41 | DispatchQueue.main.async { 42 | if (completedHandler != nil) { 43 | completedHandler!(groupImages, succeed) 44 | } 45 | } 46 | } 47 | 48 | for (index, value) in groupSource.enumerated() { 49 | 50 | let url = URL(string: AvatarConfig.urlStr(value)) 51 | guard let downUrl = url else { continue } 52 | 53 | let placeholderImage = AvatarManager.placeholderImage.backItemPlaceholderImage(itemPlaceholder, groupSource.count, index) 54 | if cacheGroupImage == nil { 55 | placeholderSum = placeholderSum + 1 56 | groupImages[index] = placeholderImage 57 | if placeholderSum == groupSource.count { 58 | callCompletedBlock() 59 | } 60 | } 61 | 62 | KingfisherManager.shared.retrieveImage(with: downUrl) { (result) in 63 | groupSum = groupSum + 1 64 | var image: UIImage? 65 | 66 | switch result { 67 | case .success(let imgResult): 68 | image = imgResult.image 69 | succeed = true 70 | case .failure(_): 71 | image = placeholderImage 72 | } 73 | groupImages[index] = image ?? placeholderImage 74 | if groupSum == groupSource.count { 75 | callCompletedBlock() 76 | } 77 | } 78 | } 79 | } 80 | } 81 | 82 | 83 | 84 | extension CacheAvatarHelper { 85 | 86 | 87 | /// 异步批量加载头像 88 | /// - Parameters: 89 | /// - groupSource: 数据源 90 | /// - itemPlaceholder: 占位图 91 | /// - completedHandler: 返回加载的图像和是否成功的tag 92 | public static func asynfetchLoadImageSource(_ groupSource: [String], _ itemPlaceholder: [UIImage]? = nil, _ completedHandler: AsynFetchImageHandler? = nil) { 93 | 94 | fetchLoadImageSource(groupSource: groupSource, cacheGroupImage: nil, itemPlaceholder: itemPlaceholder) { (unitImages, succeed) in 95 | if completedHandler != nil , succeed == true { 96 | completedHandler!(unitImages) 97 | } 98 | } 99 | } 100 | 101 | } 102 | -------------------------------------------------------------------------------- /CDDGroupAvatarSwift/NoCacheGroupAvatar/UIImage+NoCacheGroup.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UIImage+NoCacheGroup.swift 3 | // CDDGroupAvatarSwift 4 | // 5 | // Created by 陈甸甸 on 2020/3/13. 6 | // Copyright © 2020 RocketsChen. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | extension UIImage { 12 | 13 | 14 | // MARK: - 设置群图片 15 | public static func setImageAvatar(_ groupId: String, _ groupSource: [UIImage], _ size: CGSize, _ setImageHandler: GroupSetImageHandler? = nil, groupImageHandler: GroupImageHandler? = nil) { 16 | 17 | var groupImage = UIImage() 18 | 19 | let avatarBgColor = NoCacheAvatarManager.avatarBgColor 20 | let distance = NoCacheAvatarManager.distanceBetweenAvatar 21 | let avatarType = NoCacheAvatarManager.groupAvatarType 22 | let maxSource = AvatarHelper.getTypefMaxCount(groupSource, avatarType) 23 | 24 | let handler: GroupImageParamsHandler = { 25 | if setImageHandler != nil { 26 | setImageHandler!(groupImage) 27 | } 28 | if groupImageHandler != nil { 29 | groupImageHandler!(groupId, groupImage, maxSource, AvatarConfig.noCacheIdMD5(groupId, maxSource)) 30 | } 31 | } 32 | 33 | let containerSize = CGSize(width: size.width, height: size.height) 34 | groupImage = getGroupImage(maxSource, containerSize, avatarType, distance, avatarBgColor) 35 | 36 | handler() // block 37 | } 38 | 39 | 40 | 41 | // MARK: - 拼接群头像 42 | private static func getGroupImage(_ maxSource: [UIImage], _ size: CGSize, _ avatarType: DCGroupAvatarType, _ distance: CGFloat, _ avatarBgColor: UIColor) -> UIImage { 43 | 44 | var groupImage = UIImage() 45 | 46 | var itemAvaSize: CGSize = CGSize.zero 47 | var itemAvaPoint: CGPoint = CGPoint.zero 48 | let containerSize = CGSize(width: size.width, height: size.height) 49 | 50 | UIGraphicsBeginImageContextWithOptions(containerSize, false, UIScreen.main.scale) 51 | let ctx: CGContext = UIGraphicsGetCurrentContext()! 52 | ctx.setFillColor(avatarBgColor.cgColor) 53 | ctx.fill(CGRect(x: 0, y: 0, width: containerSize.width, height: containerSize.height)) 54 | 55 | if avatarType != .WeiBo { // WeChat 、QQ 56 | 57 | if avatarType == .WeChat { 58 | itemAvaSize = AvatarHelperTool.calculateSizeWeChatAvatarGroup(maxSource.count, containerSize, distance) 59 | } 60 | 61 | for (index, value) in maxSource.enumerated() { 62 | 63 | if avatarType == .QQ { 64 | itemAvaSize = AvatarHelperTool.calculateSizeQQAvatarGroup(maxSource.count, index, containerSize, distance) 65 | } 66 | 67 | var avatarImage: UIImage = value 68 | if itemAvaSize.height != itemAvaSize.width { // 当时不是1:1的时候需要裁减 默认是以中心和长的一边为准裁取短的 69 | let loginEdge: CGFloat = max(itemAvaSize.height, itemAvaSize.width) 70 | let shortEdge: CGFloat = min(itemAvaSize.height, itemAvaSize.width) 71 | avatarImage = avatarImage.cutImageView(CGSize(width: loginEdge, height: loginEdge), CGRect(x: (loginEdge - shortEdge) * 0.5, y: 0, width: shortEdge, height: loginEdge)) 72 | } 73 | 74 | itemAvaPoint = AvatarHelperTool.calculatePointAvatarGroup(maxSource.count, index, containerSize, distance, avatarType) 75 | let avaRect: CGRect = CGRect(x: itemAvaPoint.x, y: itemAvaPoint.y, width: itemAvaSize.width, height: itemAvaSize.height) 76 | avatarImage .draw(in: avaRect) 77 | } 78 | 79 | }else { // WeiBo 80 | 81 | let bordWidth: CGFloat = NoCacheAvatarManager.bordWidth 82 | let radius: CGFloat = AvatarHelperTool.calculateRadiusWeiBoAvatarGroup(maxSource.count, containerSize, distance) 83 | 84 | for (index, value) in maxSource.enumerated() { 85 | 86 | let avatarImage = value.cgContextAddArcToPointImage(bordWidth, avatarBgColor) 87 | ctx.saveGState() 88 | itemAvaPoint = AvatarHelperTool.calculateWeiBoAvatarGroup(maxSource.count, index, containerSize, distance) 89 | ctx.addArc(center: CGPoint(x: itemAvaPoint.x, y: itemAvaPoint.y), radius: radius, startAngle: 0, endAngle: CGFloat.pi * 2, clockwise: true) 90 | ctx.closePath() 91 | ctx.clip() 92 | let avatarRect: CGRect = CGRect(x: itemAvaPoint.x - radius, y: itemAvaPoint.y - radius, width: radius * 2, height: radius * 2) 93 | avatarImage.draw(in: avatarRect) 94 | ctx.restoreGState() 95 | } 96 | 97 | } 98 | 99 | groupImage = UIGraphicsGetImageFromCurrentImageContext()! 100 | UIGraphicsEndImageContext() 101 | 102 | if (avatarType == .QQ) { 103 | groupImage = groupImage.cgContextAddArcToPointImage(0, .clear) 104 | } 105 | 106 | return groupImage 107 | } 108 | 109 | } 110 | -------------------------------------------------------------------------------- /CDDGroupAvatarSwift/CacheGroupAvatar/UIImage+Group.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UIImage+Group.swift 3 | // CDDGroupAvatarSwift 4 | // 5 | // Created by 陈甸甸 on 2020/3/15. 6 | // Copyright © 2020 RocketsChen. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import Kingfisher 11 | 12 | extension UIImage { 13 | 14 | // MARK: - 设置群图片 15 | public static func setCacheImageAvatar(_ groupId: String, _ groupSource: [String], _ itemPlaceholder: [UIImage]? = nil,_ size: CGSize, _ options: DCGroupAvatarCacheType? = .Default, _ setImageHandler: GroupSetImageHandler? = nil, groupImageHandler: GroupImageHandler? = nil) { 16 | 17 | var groupUnitImages = [UIImage]() 18 | 19 | let avatarBgColor = AvatarManager.avatarBgColor 20 | let distance = AvatarManager.distanceBetweenAvatar 21 | let avatarType = AvatarManager.groupAvatarType 22 | let maxSource = AvatarHelper.getTypefMaxCount(groupSource, avatarType) 23 | let md5Str = AvatarConfig.cacheIdMD5(groupId, maxSource) 24 | var groupImage = AvatarManager.placeholderImage 25 | var isCachedSave: Bool = false 26 | 27 | let handler: GroupImageParamsHandler = { 28 | if setImageHandler != nil { 29 | setImageHandler!(groupImage) 30 | } 31 | if groupImageHandler != nil { 32 | groupImageHandler!(groupId, groupImage, groupUnitImages, AvatarConfig.cacheIdMD5(groupId, maxSource)) 33 | } 34 | } 35 | 36 | if let image = ImageCache.default.retrieveImageInMemoryCache(forKey: md5Str) { 37 | groupImage = image 38 | isCachedSave = true 39 | if options == .Default { 40 | groupUnitImages = CacheAvatarHelper.fetchItemCacheArraySource(maxSource) 41 | handler() 42 | if groupUnitImages.count == maxSource.count { return } 43 | } 44 | } 45 | CacheAvatarHelper.fetchLoadImageSource(groupSource: maxSource, cacheGroupImage: !isCachedSave ? nil : groupImage, itemPlaceholder: itemPlaceholder) {(unitImages, succeed) in 46 | groupUnitImages = unitImages 47 | let containerSize = CGSize(width: size.width, height: size.height) 48 | groupImage = cacheGroupImage(groupUnitImages, containerSize, avatarType, distance, avatarBgColor) 49 | ImageCache.default.store(groupImage, forKey: md5Str, toDisk: true) 50 | 51 | handler() // block 52 | } 53 | } 54 | 55 | 56 | // MARK: - 拼接群头像 57 | private static func cacheGroupImage(_ maxSource: [UIImage], _ size: CGSize, _ avatarType: DCGroupAvatarType, _ distance: CGFloat, _ avatarBgColor: UIColor) -> UIImage { 58 | 59 | var groupImage = UIImage() 60 | var itemAvaSize: CGSize = CGSize.zero 61 | var itemAvaPoint: CGPoint = CGPoint.zero 62 | let containerSize = CGSize(width: size.width, height: size.height) 63 | 64 | UIGraphicsBeginImageContextWithOptions(containerSize, false, UIScreen.main.scale) 65 | let ctx: CGContext = UIGraphicsGetCurrentContext()! 66 | ctx.setFillColor(avatarBgColor.cgColor) 67 | ctx.fill(CGRect(x: 0, y: 0, width: containerSize.width, height: containerSize.height)) 68 | 69 | if avatarType != .WeiBo { // WeChat 、QQ 70 | 71 | if avatarType == .WeChat { 72 | itemAvaSize = AvatarHelperTool.calculateSizeWeChatAvatarGroup(maxSource.count, containerSize, distance) 73 | } 74 | 75 | for (index, value) in maxSource.enumerated() { 76 | 77 | if avatarType == .QQ { 78 | itemAvaSize = AvatarHelperTool.calculateSizeQQAvatarGroup(maxSource.count, index, containerSize, distance) 79 | } 80 | 81 | var avatarImage: UIImage = value 82 | if itemAvaSize.height != itemAvaSize.width { // 当时不是1:1的时候需要裁减 默认是以中心和长的一边为准裁取短的 83 | let loginEdge: CGFloat = max(itemAvaSize.height, itemAvaSize.width) 84 | let shortEdge: CGFloat = min(itemAvaSize.height, itemAvaSize.width) 85 | avatarImage = avatarImage.cutImageView(CGSize(width: loginEdge, height: loginEdge), CGRect(x: (loginEdge - shortEdge) * 0.5, y: 0, width: shortEdge, height: loginEdge)) 86 | } 87 | 88 | itemAvaPoint = AvatarHelperTool.calculatePointAvatarGroup(maxSource.count, index, containerSize, distance, avatarType) 89 | let avaRect: CGRect = CGRect(x: itemAvaPoint.x, y: itemAvaPoint.y, width: itemAvaSize.width, height: itemAvaSize.height) 90 | avatarImage .draw(in: avaRect) 91 | } 92 | 93 | }else { // WeiBo 94 | 95 | let bordWidth: CGFloat = AvatarManager.bordWidth 96 | let radius: CGFloat = AvatarHelperTool.calculateRadiusWeiBoAvatarGroup(maxSource.count, containerSize, distance) 97 | 98 | for (index, value) in maxSource.enumerated() { 99 | 100 | let avatarImage = value.cgContextAddArcToPointImage(bordWidth, avatarBgColor) 101 | ctx.saveGState() 102 | itemAvaPoint = AvatarHelperTool.calculateWeiBoAvatarGroup(maxSource.count, index, containerSize, distance) 103 | ctx.addArc(center: CGPoint(x: itemAvaPoint.x, y: itemAvaPoint.y), radius: radius, startAngle: 0, endAngle: CGFloat.pi * 2, clockwise: true) 104 | ctx.closePath() 105 | ctx.clip() 106 | let avatarRect: CGRect = CGRect(x: itemAvaPoint.x - radius, y: itemAvaPoint.y - radius, width: radius * 2, height: radius * 2) 107 | avatarImage.draw(in: avatarRect) 108 | ctx.restoreGState() 109 | } 110 | 111 | } 112 | 113 | groupImage = UIGraphicsGetImageFromCurrentImageContext()! 114 | UIGraphicsEndImageContext() 115 | 116 | if (avatarType == .QQ) { 117 | groupImage = groupImage.cgContextAddArcToPointImage(0, .clear) 118 | } 119 | 120 | return groupImage 121 | } 122 | 123 | } 124 | -------------------------------------------------------------------------------- /Demo/CDDGroupAvatarSwift/CDDGroupAvatarSwift/TestViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TestViewController.swift 3 | // CDDGroupAvatarSwift 4 | // 5 | // Created by 陈甸甸 on 2020/3/8. 6 | //Copyright © 2020 RocketsChen. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import Kingfisher 11 | 12 | 13 | fileprivate enum Reusable { 14 | 15 | static let TestCellID = "TestCell" 16 | } 17 | 18 | 19 | class TestViewController: UITableViewController { 20 | 21 | 22 | // MARK: - LazyLoad 23 | private lazy var groupArray = [TestItem]() 24 | 25 | // MARK: - LifeCycle 26 | override func viewDidLoad() { 27 | super.viewDidLoad() 28 | 29 | setUpUI() 30 | 31 | setUpData() 32 | } 33 | 34 | deinit { 35 | print("----deinit") 36 | } 37 | } 38 | 39 | // MARK: - 设置 UI 界面 40 | extension TestViewController { 41 | 42 | fileprivate func setUpUI() { 43 | 44 | view.backgroundColor = .white 45 | 46 | AvatarManager.baseUrl = "http://ww1.sinaimg.cn/small/" 47 | AvatarManager.groupAvatarType = .WeChat 48 | AvatarManager.placeholderImage = UIImage(named: "avatarholder")! 49 | 50 | setupNav() 51 | setUpTabView() 52 | } 53 | 54 | 55 | fileprivate func setUpData() { 56 | 57 | groupArray.removeAll() 58 | 59 | let array: [[String]] = [["006tNc79gy1g5fmoexlt6j30u00vxqrb.jpg", "006tNc79gy1g5fmofi07aj30u00uwqqk.jpg", "006tNc79gy1g5fln5crn5j30u00u00vh.jpg", "006tNc79gy1g5fln52xz8j30u00u0411.jpg", "006tNc79gy1g5fmtvyydxj30u00u0x6r.jpg", "006tNc79gy1g5fmogr9fsj30u00uz4m9.jpg", "006tNc79gy1g5fmogcjidj30u00wc7su.jpg", "006tNc79gy1g5fmofvp9cj30u00w8kft.jpg", "006tNc79gy1g5fmofvp9cj30u00w8kft.jpg"], ["006tNc79gy1g5fln52xz8j30u00u0411.jpg", "006tNc79gy1g5fln5crn5j30u00u00vh.jpg", "006tNc79gy1g5fli2qszgj30ku0ii0ua.jpg", "006tNc79gy1g5fli1g0wtj30rs0rs416.jpg", "006tNc79gy1g5fli2zfzwj30qo0qojvv.jpg", "006tNc79gy1g5fli3fr0oj30u00u2goh.jpg", "006tNc79gy1g56or92vvmj30u00u048a.jpg", "006tNc79gy1g56mcmorgrj30rk0nm0ze.jpg", "006tNc79gy1g57h4j42ppj30u00u00vy.jpg"], ["006tNc79gy1g57hfrnhe6j30u00w01eu.jpg", "006tNc79gy1g56or92vvmj30u00u048a.jpg", "006tNc79gy1g57h4j42ppj30u00u00vy.jpg", "1.jpg", "006tNc79gy1g57h4j42ppj30u00u00vy.jpg" ,"1.jpg", "006tNc79gy1g5fli2j5x4j30u00u2ack.jpg", "006tNc79gy1g5fli3fr0oj30u00u2goh.jpg", "006tNc79gy1g57h4j42ppj30u00u00vy.jpg"]]; 60 | 61 | for i in 0..<24 { 62 | 63 | var item = TestItem() 64 | item.groupId = "群头id-\(i)" 65 | let index: Int = i / 8 66 | let count: Int = i % 8 67 | 68 | let itemArray = array[index] as NSArray 69 | let groupSource = itemArray.subarray(with: NSMakeRange(0, min(itemArray.count, count + 2))) as? [String] 70 | item.groupSource = groupSource 71 | groupArray.append(item) 72 | } 73 | 74 | } 75 | 76 | func setupNav() { 77 | 78 | navigationItem.rightBarButtonItem = UIBarButtonItem(title: "clean", style: .done, target: self, action: #selector(clean)) 79 | navigationItem.rightBarButtonItem?.tintColor = .black 80 | } 81 | 82 | 83 | func setUpTabView() { 84 | 85 | tableView.rowHeight = 80 86 | tableView.tableFooterView = UIView() 87 | tableView.register(TestCell.self, forCellReuseIdentifier: Reusable.TestCellID) 88 | } 89 | 90 | 91 | } 92 | 93 | 94 | extension TestViewController { 95 | 96 | 97 | override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 98 | groupArray.count 99 | } 100 | 101 | 102 | override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 103 | 104 | let cell = tableView.dequeueReusableCell(withIdentifier: Reusable.TestCellID, for: indexPath) as! TestCell 105 | 106 | cell.groupIdLabel.text = groupArray[indexPath.row].groupId 107 | cell.groupIamgeView.setImageAvatar(groupId: groupArray[indexPath.row].groupId, groupSource:groupArray[indexPath.row].groupSource) { (groupId, groupImage, itemImageArray, cacheId) in 108 | cell.cacheIdLabel.text = cacheId 109 | } 110 | 111 | return cell 112 | } 113 | 114 | 115 | override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 116 | 117 | tableView.deselectRow(at: indexPath, animated: true) 118 | } 119 | 120 | } 121 | 122 | 123 | extension TestViewController { 124 | 125 | // MARK: - 清理缓存 126 | @objc func clean() { 127 | 128 | ImageCache.default.clearDiskCache() 129 | ImageCache.default.clearMemoryCache() 130 | ImageCache.default.cleanExpiredDiskCache { [weak self] in 131 | guard let self = self else { return } 132 | self.tableView.reloadData() 133 | } 134 | 135 | } 136 | } 137 | 138 | 139 | 140 | public struct TestItem { 141 | 142 | var groupId: String! 143 | var groupSource: [String]! 144 | } 145 | 146 | 147 | class TestCell: UITableViewCell { 148 | 149 | /// Control 150 | let groupIamgeView = UIImageView() 151 | let groupIdLabel = UILabel() 152 | let cacheIdLabel = UILabel() 153 | 154 | override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { 155 | super.init(style: style, reuseIdentifier: reuseIdentifier) 156 | 157 | setUpUI() 158 | } 159 | 160 | required init?(coder: NSCoder) { 161 | fatalError("init(coder:) has not been implemented") 162 | } 163 | 164 | 165 | func setUpUI() { 166 | 167 | contentView.addSubview(groupIamgeView) 168 | contentView.addSubview(groupIdLabel) 169 | contentView.addSubview(cacheIdLabel) 170 | groupIdLabel.font = UIFont.systemFont(ofSize: 18) 171 | cacheIdLabel.font = UIFont.systemFont(ofSize: 15) 172 | cacheIdLabel.textColor = .lightGray 173 | 174 | groupIamgeView.frame = CGRect(x: 12, y: 10, width: 60, height: 60) 175 | } 176 | 177 | override func layoutSubviews() { 178 | super.layoutSubviews() 179 | 180 | groupIdLabel.frame = CGRect(x: 82, y: 10, width: self.frame.size.width - 92, height: 30) 181 | cacheIdLabel.frame = CGRect(x: 82, y: 44, width: self.frame.size.width - 92, height: 20) 182 | } 183 | 184 | } 185 | -------------------------------------------------------------------------------- /Demo/CDDGroupAvatarSwift/CDDGroupAvatarSwift/PFS/KMCGeigerCounter/KMCGeigerCounter.m: -------------------------------------------------------------------------------- 1 | // 2 | // KMCGeigerCounter.m 3 | // KMCGeigerCounter 4 | // 5 | // Created by Kevin Conner on 10/21/14. 6 | // Copyright (c) 2014 Kevin Conner. All rights reserved. 7 | // 8 | 9 | #import "KMCGeigerCounter.h" 10 | #import 11 | 12 | #define isXDevice (([[UIScreen mainScreen] respondsToSelector:@selector(nativeBounds)] ? [UIScreen mainScreen].nativeBounds.size.height/[UIScreen mainScreen].nativeScale : [UIScreen mainScreen].bounds.size.height) > 800.0) 13 | 14 | @interface KMCGeigerCounter () 15 | 16 | @property (nonatomic, readwrite, assign, getter = isRunning) BOOL running; 17 | 18 | @property (nonatomic, strong) UIWindow *window; 19 | @property (nonatomic, strong) UILabel *meterLabel; 20 | @property (nonatomic, strong) UIColor *meterPerfectColor; 21 | @property (nonatomic, strong) UIColor *meterGoodColor; 22 | @property (nonatomic, strong) UIColor *meterBadColor; 23 | 24 | @property (nonatomic, strong) CADisplayLink *displayLink; 25 | @property (nonatomic, assign) SystemSoundID tickSoundID; 26 | 27 | @property (nonatomic, assign) NSInteger frameNumber; 28 | 29 | @property (nonatomic, assign) NSInteger hardwareFramesPerSecond; 30 | @property (nonatomic, assign) CFTimeInterval *recentFrameTimes; // malloc: CFTimeInterval[hardwareFramesPerSecond] 31 | 32 | @end 33 | 34 | @implementation KMCGeigerCounter 35 | 36 | #pragma mark - Helpers 37 | 38 | + (UIColor *)colorWithHex:(uint32_t)hex alpha:(CGFloat)alpha 39 | { 40 | CGFloat red = (CGFloat) ((hex & 0xff0000) >> 16) / 255.0f; 41 | CGFloat green = (CGFloat) ((hex & 0x00ff00) >> 8) / 255.0f; 42 | CGFloat blue = (CGFloat) (hex & 0x0000ff) / 255.0f; 43 | return [UIColor colorWithRed:red green:green blue:blue alpha:alpha]; 44 | } 45 | 46 | - (CFTimeInterval)lastFrameTime 47 | { 48 | return _recentFrameTimes[self.frameNumber % self.hardwareFramesPerSecond]; 49 | } 50 | 51 | - (void)recordFrameTime:(CFTimeInterval)frameTime 52 | { 53 | ++self.frameNumber; 54 | _recentFrameTimes[self.frameNumber % self.hardwareFramesPerSecond] = frameTime; 55 | } 56 | 57 | - (void)clearLastSecondOfFrameTimes 58 | { 59 | CFTimeInterval initialFrameTime = CACurrentMediaTime(); 60 | for (NSInteger i = 0; i < self.hardwareFramesPerSecond; ++i) { 61 | _recentFrameTimes[i] = initialFrameTime; 62 | } 63 | self.frameNumber = 0; 64 | } 65 | 66 | - (void)updateMeterLabel 67 | { 68 | NSInteger droppedFrameCount = self.droppedFrameCountInLastSecond; 69 | NSInteger drawnFrameCount = self.drawnFrameCountInLastSecond; 70 | 71 | NSString *droppedString; 72 | NSString *drawnString; 73 | 74 | if (droppedFrameCount <= 0) { 75 | self.meterLabel.backgroundColor = self.meterPerfectColor; 76 | 77 | droppedString = @"--"; 78 | } else { 79 | if (droppedFrameCount <= 2) { 80 | self.meterLabel.backgroundColor = self.meterGoodColor; 81 | } else { 82 | self.meterLabel.backgroundColor = self.meterBadColor; 83 | } 84 | 85 | droppedString = [NSString stringWithFormat:@"%ld", (long) droppedFrameCount]; 86 | } 87 | 88 | if (drawnFrameCount == -1) { 89 | drawnString = @"--"; 90 | } else { 91 | drawnString = [NSString stringWithFormat:@"%ld", (long) drawnFrameCount]; 92 | } 93 | 94 | self.meterLabel.text = [NSString stringWithFormat:@"%@ %@", droppedString, drawnString]; 95 | } 96 | 97 | - (CFTimeInterval)hardwareFrameDuration 98 | { 99 | return 1.0 / self.hardwareFramesPerSecond; 100 | } 101 | 102 | - (void)displayLinkWillDraw:(CADisplayLink *)displayLink 103 | { 104 | CFTimeInterval currentFrameTime = displayLink.timestamp; 105 | CFTimeInterval frameDuration = currentFrameTime - [self lastFrameTime]; 106 | 107 | // Frames should be even multiples of hardwareFrameDuration. 108 | // If a frame takes two frame durations, we dropped at least one, so click. 109 | if (1.5 < frameDuration / [self hardwareFrameDuration]) { 110 | AudioServicesPlaySystemSound(self.tickSoundID); 111 | } 112 | 113 | [self recordFrameTime:currentFrameTime]; 114 | 115 | [self updateMeterLabel]; 116 | } 117 | 118 | #pragma mark - 119 | 120 | - (void)start 121 | { 122 | NSURL *tickSoundURL = [[NSBundle bundleForClass:KMCGeigerCounter.class] URLForResource:@"KMCGeigerCounterTick" withExtension:@"aiff"]; 123 | SystemSoundID tickSoundID; 124 | AudioServicesCreateSystemSoundID((__bridge CFURLRef) tickSoundURL, &tickSoundID); 125 | self.tickSoundID = tickSoundID; 126 | 127 | self.displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(displayLinkWillDraw:)]; 128 | [self.displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes]; 129 | [self clearLastSecondOfFrameTimes]; 130 | } 131 | 132 | - (void)stop 133 | { 134 | [self.displayLink invalidate]; 135 | self.displayLink = nil; 136 | 137 | AudioServicesDisposeSystemSoundID(self.tickSoundID); 138 | self.tickSoundID = 0; 139 | } 140 | 141 | - (void)setRunning:(BOOL)running 142 | { 143 | if (_running != running) { 144 | if (running) { 145 | [self start]; 146 | } else { 147 | [self stop]; 148 | } 149 | 150 | _running = running; 151 | } 152 | } 153 | 154 | #pragma mark - 155 | 156 | - (void)applicationDidBecomeActive 157 | { 158 | self.running = self.enabled; 159 | } 160 | 161 | - (void)applicationWillResignActive 162 | { 163 | self.running = NO; 164 | } 165 | 166 | #pragma mark - 167 | 168 | - (void)enable 169 | { 170 | self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; 171 | self.window.rootViewController = [[UIViewController alloc] init]; 172 | self.window.windowLevel = self.windowLevel; 173 | self.window.userInteractionEnabled = NO; 174 | 175 | CGFloat const kMeterWidth = 105.0; 176 | CGFloat xOrigin = 0.0; 177 | UIViewAutoresizing autoresizingMask = UIViewAutoresizingFlexibleBottomMargin; 178 | switch (self.position) { 179 | case KMCGeigerCounterPositionLeft: 180 | xOrigin = 0.0; 181 | autoresizingMask |= UIViewAutoresizingFlexibleRightMargin; 182 | break; 183 | case KMCGeigerCounterPositionMiddle: 184 | xOrigin = (CGRectGetWidth(self.window.bounds) - kMeterWidth) / 2.0; 185 | autoresizingMask |= UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin; 186 | break; 187 | case KMCGeigerCounterPositionRight: 188 | xOrigin = (CGRectGetWidth(self.window.bounds) - kMeterWidth); 189 | autoresizingMask |= UIViewAutoresizingFlexibleLeftMargin; 190 | break; 191 | } 192 | 193 | CGFloat meterHeight = 20; 194 | self.meterLabel = [[UILabel alloc] initWithFrame:CGRectMake(xOrigin, isXDevice ? 35.0 : 5.0, 195 | kMeterWidth, meterHeight)]; 196 | self.meterLabel.autoresizingMask = autoresizingMask; 197 | self.meterLabel.font = [UIFont boldSystemFontOfSize:12.0]; 198 | self.meterLabel.backgroundColor = [UIColor grayColor]; 199 | self.meterLabel.textColor = [UIColor whiteColor]; 200 | self.meterLabel.textAlignment = NSTextAlignmentCenter; 201 | [self.window.rootViewController.view addSubview:self.meterLabel]; 202 | 203 | self.window.hidden = NO; 204 | 205 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidBecomeActive) name:UIApplicationDidBecomeActiveNotification object:nil]; 206 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillResignActive) name:UIApplicationWillResignActiveNotification object:nil]; 207 | 208 | if ([UIApplication sharedApplication].applicationState == UIApplicationStateActive) { 209 | self.running = YES; 210 | } 211 | } 212 | 213 | - (void)disable 214 | { 215 | [[NSNotificationCenter defaultCenter] removeObserver:self]; 216 | 217 | self.running = NO; 218 | 219 | self.meterLabel = nil; 220 | self.window = nil; 221 | } 222 | 223 | #pragma mark - Init/dealloc 224 | 225 | - (instancetype)init 226 | { 227 | self = [super init]; 228 | if (self) { 229 | _windowLevel = UIWindowLevelStatusBar + 10.0; 230 | _position = KMCGeigerCounterPositionLeft; 231 | 232 | _meterPerfectColor = [KMCGeigerCounter colorWithHex:0x999999 alpha:1.0]; 233 | _meterGoodColor = [KMCGeigerCounter colorWithHex:0x66a300 alpha:1.0]; 234 | _meterBadColor = [KMCGeigerCounter colorWithHex:0xff7f0d alpha:1.0]; 235 | 236 | if (@available(iOS 10.3, *)) { 237 | _hardwareFramesPerSecond = [UIScreen mainScreen].maximumFramesPerSecond; 238 | } else { 239 | _hardwareFramesPerSecond = 60; 240 | } 241 | 242 | _recentFrameTimes = malloc(sizeof(*_recentFrameTimes) * _hardwareFramesPerSecond); 243 | } 244 | return self; 245 | } 246 | 247 | - (void)dealloc 248 | { 249 | [_displayLink invalidate]; 250 | 251 | if (_tickSoundID) { 252 | AudioServicesDisposeSystemSoundID(_tickSoundID); 253 | } 254 | 255 | [[NSNotificationCenter defaultCenter] removeObserver:self]; 256 | 257 | if (_recentFrameTimes) { 258 | free(_recentFrameTimes); 259 | _recentFrameTimes = nil; 260 | } 261 | } 262 | 263 | #pragma mark - Public interface 264 | 265 | + (instancetype)sharedGeigerCounter 266 | { 267 | static KMCGeigerCounter *instance; 268 | static dispatch_once_t onceToken; 269 | dispatch_once(&onceToken, ^{ 270 | instance = [[KMCGeigerCounter alloc] init]; 271 | }); 272 | return instance; 273 | } 274 | 275 | - (void)setEnabled:(BOOL)enabled 276 | { 277 | if (_enabled != enabled) { 278 | if (enabled) { 279 | [self enable]; 280 | } else { 281 | [self disable]; 282 | } 283 | 284 | _enabled = enabled; 285 | } 286 | } 287 | 288 | - (void)setWindowLevel:(UIWindowLevel)windowLevel 289 | { 290 | _windowLevel = windowLevel; 291 | self.window.windowLevel = windowLevel; 292 | } 293 | 294 | - (NSInteger)droppedFrameCountInLastSecond 295 | { 296 | NSInteger droppedFrameCount = 0; 297 | 298 | CFTimeInterval lastFrameTime = CACurrentMediaTime() - [self hardwareFrameDuration]; 299 | for (NSInteger i = 0; i < self.hardwareFramesPerSecond; ++i) { 300 | if (1.0 <= lastFrameTime - _recentFrameTimes[i]) { 301 | ++droppedFrameCount; 302 | } 303 | } 304 | 305 | return droppedFrameCount; 306 | } 307 | 308 | - (NSInteger)drawnFrameCountInLastSecond 309 | { 310 | if (!self.running || self.frameNumber < self.hardwareFramesPerSecond) { 311 | return -1; 312 | } 313 | 314 | return self.hardwareFramesPerSecond - self.droppedFrameCountInLastSecond; 315 | } 316 | 317 | @end 318 | -------------------------------------------------------------------------------- /Demo/CDDGroupAvatarSwift/CDDGroupAvatarSwift/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // CDDGroupAvatarSwift 4 | // 5 | // Created by 陈甸甸 on 2020/3/8. 6 | // Copyright © 2020 RocketsChen. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import Kingfisher 11 | 12 | class ViewController: UIViewController { 13 | 14 | /// WeChat 15 | @IBOutlet weak var avImageViewW2: UIImageView! 16 | @IBOutlet weak var avImageViewW3: UIImageView! 17 | @IBOutlet weak var avImageViewW4: UIImageView! 18 | @IBOutlet weak var avImageViewW5: UIImageView! 19 | @IBOutlet weak var avImageViewW6: UIImageView! 20 | @IBOutlet weak var avImageViewW7: UIImageView! 21 | @IBOutlet weak var avImageViewW8: UIImageView! 22 | @IBOutlet weak var avImageViewW9: UIImageView! 23 | 24 | 25 | // QQ 26 | @IBOutlet weak var avImageViewNQ2: UIImageView! 27 | @IBOutlet weak var avImageViewNQ3: UIImageView! 28 | @IBOutlet weak var avImageViewNQ4: UIImageView! 29 | 30 | // WeBo 31 | @IBOutlet weak var avImageViewWeiBo2: UIImageView! 32 | @IBOutlet weak var avImageViewWeiBo3: UIImageView! 33 | @IBOutlet weak var avImageViewWeiBo4: UIImageView! 34 | 35 | 36 | /// NoCache 37 | @IBOutlet weak var ncImageViewW1: UIImageView! 38 | @IBOutlet weak var ncImageViewW2: UIImageView! 39 | @IBOutlet weak var ncImageViewW3: UIImageView! 40 | @IBOutlet weak var ncImageViewW4: UIImageView! 41 | @IBOutlet weak var ncImageViewW5: UIImageView! 42 | @IBOutlet weak var ncImageViewW6: UIImageView! 43 | 44 | /// Button 45 | @IBOutlet weak var avaButton: UIButton! 46 | @IBOutlet weak var avaBgButton: UIButton! 47 | 48 | // MARK: - LifeCycle 49 | override func viewDidLoad() { 50 | super.viewDidLoad() 51 | 52 | setUpUI() 53 | } 54 | 55 | } 56 | 57 | 58 | // MARK: - 设置 UI 界面 59 | extension ViewController { 60 | 61 | fileprivate func setUpUI() { 62 | 63 | view.backgroundColor = .white 64 | 65 | title = "CDDGroupAvatarSwift" 66 | 67 | setUpLoadData() 68 | } 69 | 70 | 71 | func setupNav() { 72 | 73 | navigationItem.rightBarButtonItem = UIBarButtonItem(title: "table", style: .done, target: self, action: #selector(goToTest)) 74 | navigationItem.leftBarButtonItem = UIBarButtonItem(title: "clean", style: .done, target: self, action: #selector(clean)) 75 | navigationItem.rightBarButtonItem?.tintColor = .black 76 | navigationItem.leftBarButtonItem?.tintColor = .black 77 | } 78 | 79 | 80 | func setUpLoadData() { 81 | 82 | setupNav() 83 | 84 | setUpCache() 85 | 86 | setUpNoCache() 87 | } 88 | 89 | override func touchesBegan(_ touches: Set, with event: UIEvent?) { 90 | 91 | /// 异步加载头像 92 | // CacheAvatarHelper.asynfetchLoadImageSource(["006tNc79gy1g56or92vvmj30u00u048a.jpg", "006tNc79gy1g56mcmorgrj30rk0nm0ze.jpg", "006tNc79gy1g57h4j42ppj30u00u00vy.jpg"], nil) { (unitImages) in 93 | // print(unitImages) 94 | // } 95 | 96 | setUpLoadData() 97 | } 98 | 99 | } 100 | 101 | 102 | extension ViewController { 103 | 104 | func setUpCache() { 105 | 106 | AvatarManager.baseUrl = "http://ww1.sinaimg.cn/small/" 107 | AvatarManager.placeholderImage = UIImage(named: "avatarholder")! 108 | 109 | setUpWeiChatCache() 110 | setUpNewQQCache() 111 | setUpWeiBoCache() 112 | 113 | } 114 | 115 | 116 | // MARK: - WeiChat 117 | func setUpWeiChatCache() { 118 | 119 | AvatarManager.groupAvatarType = .WeChat 120 | AvatarManager.distanceBetweenAvatar = 2 121 | 122 | avImageViewW2.setImageAvatar(groupId: "avImageViewW2", groupSource: ["1","2"], itemPlaceholder: [UIImage(named: "man")!, UIImage(named: "woman")!]) 123 | avImageViewW3.setImageAvatar(groupId: "avImageViewW3", groupSource: ["006tNc79gy1g56or92vvmj30u00u048a.jpg", "006tNc79gy1g56mcmorgrj30rk0nm0ze.jpg", "006tNc79gy1g57h4j42ppj30u00u00vy.jpg"]) 124 | avImageViewW4.setImageAvatar(groupId: "avImageViewW4", groupSource: ["006tNc79gy1g56or92vvmj30u00u048a.jpg", "006tNc79gy1g56mcmorgrj30rk0nm0ze.jpg", "006tNc79gy1g57h4j42ppj30u00u00vy.jpg", "006tNc79gy1g57hfrnhe6j30u00w01eu.jpg"]) 125 | avImageViewW5.setImageAvatar(groupId: "avImageViewW5", groupSource: ["006tNc79gy1g56or92vvmj30u00u048a.jpg","006tNc79gy1g56mcmorgrj30rk0nm0ze.jpg","006tNc79gy1g57h4j42ppj30u00u00vy.jpg","006tNc79gy1g57hfrnhe6j30u00w01eu.jpg","006tNc79gy1g56or92vvmj30u00u048a.jpg"]) 126 | avImageViewW6.setImageAvatar(groupId: "avImageViewW6", groupSource: ["006tNc79gy1g56or92vvmj30u00u048a.jpg","006tNc79gy1g56mcmorgrj30rk0nm0ze.jpg","006tNc79gy1g57h4j42ppj30u00u00vy.jpg","006tNc79gy1g57hfrnhe6j30u00w01eu.jpg","006tNc79gy1g56or92vvmj30u00u048a.jpg","006tNc79gy1g57h4j42ppj30u00u00vy.jpg"]) 127 | avImageViewW7.setImageAvatar(groupId: "avImageViewW7", groupSource: ["006tNc79gy1g56or92vvmj30u00u048a.jpg","006tNc79gy1g56mcmorgrj30rk0nm0ze.jpg","006tNc79gy1g57h4j42ppj30u00u00vy.jpg","006tNc79gy1g57hfrnhe6j30u00w01eu.jpg","006tNc79gy1g56or92vvmj30u00u048a.jpg","006tNc79gy1g57h4j42ppj30u00u00vy.jpg","006tNc79gy1g56or92vvmj30u00u048a.jpg"]) 128 | avImageViewW8.setImageAvatar(groupId: "avImageViewW8", groupSource: ["006tNc79gy1g56or92vvmj30u00u048a.jpg","006tNc79gy1g56mcmorgrj30rk0nm0ze.jpg","006tNc79gy1g57h4j42ppj30u00u00vy.jpg","006tNc79gy1g57hfrnhe6j30u00w01eu.jpg","006tNc79gy1g56or92vvmj30u00u048a.jpg","006tNc79gy1g57h4j42ppj30u00u00vy.jpg","006tNc79gy1g56or92vvmj30u00u048a.jpg","006tNc79gy1g57h4j42ppj30u00u00vy.jpg"]) 129 | avImageViewW9.setImageAvatar(groupId: "avImageViewW9", groupSource: ["006tNc79gy1g56or92vvmj30u00u048a.jpg","006tNc79gy1g56mcmorgrj30rk0nm0ze.jpg","006tNc79gy1g57h4j42ppj30u00u00vy.jpg","006tNc79gy1g57hfrnhe6j30u00w01eu.jpg","006tNc79gy1g56or92vvmj30u00u048a.jpg","006tNc79gy1g57h4j42ppj30u00u00vy.jpg","006tNc79gy1g56or92vvmj30u00u048a.jpg","006tNc79gy1g57h4j42ppj30u00u00vy.jpg","006tNc79gy1g57h4j42ppj30u00u00vy.jpg"]) 130 | 131 | } 132 | 133 | 134 | // MARK: - NewQQ 135 | func setUpNewQQCache() { 136 | 137 | AvatarManager.groupAvatarType = .QQ 138 | AvatarManager.distanceBetweenAvatar = 1 139 | 140 | avImageViewNQ2.setImageAvatar(groupId: "avImageViewNQ2", groupSource: ["1","2"], itemPlaceholder: [UIImage(named: "man")!, UIImage(named: "woman")!]) 141 | avImageViewNQ3.setImageAvatar(groupId: "avImageViewNQ3", groupSource: ["006tNc79gy1g56or92vvmj30u00u048a.jpg", "006tNc79gy1g56mcmorgrj30rk0nm0ze.jpg", "006tNc79gy1g57h4j42ppj30u00u00vy.jpg", "006tNc79gy1g57h4j42ppj30u00u00vy.jpg"]) 142 | avImageViewNQ4.setImageAvatar(groupId: "avImageViewNQ4", groupSource: ["006tNc79gy1g56or92vvmj30u00u048a.jpg", "006tNc79gy1g56mcmorgrj30rk0nm0ze.jpg", "006tNc79gy1g57h4j42ppj30u00u00vy.jpg", "006tNc79gy1g57h4j42ppj30u00u00vy.jpg", "006tNc79gy1g57hfrnhe6j30u00w01eu.jpg"]) 143 | } 144 | 145 | 146 | // MARK: - WeiBo 147 | func setUpWeiBoCache() { 148 | 149 | AvatarManager.groupAvatarType = .WeiBo 150 | AvatarManager.distanceBetweenAvatar = 2 151 | 152 | avImageViewWeiBo2.setImageAvatar(groupId: "avImageViewWeiBo2", groupSource: ["1","2"], itemPlaceholder: [UIImage(named: "man")!, UIImage(named: "woman")!]) 153 | avImageViewWeiBo3.setImageAvatar(groupId: "avImageViewWeiBo3", groupSource: ["006tNc79gy1g56or92vvmj30u00u048a.jpg", "006tNc79gy1g56mcmorgrj30rk0nm0ze.jpg", "006tNc79gy1g57h4j42ppj30u00u00vy.jpg", "006tNc79gy1g57h4j42ppj30u00u00vy.jpg"]) 154 | avImageViewWeiBo4.setImageAvatar(groupId: "avImageViewWeiBo4", groupSource: ["006tNc79gy1g56or92vvmj30u00u048a.jpg", "006tNc79gy1g56mcmorgrj30rk0nm0ze.jpg", "006tNc79gy1g57h4j42ppj30u00u00vy.jpg", "006tNc79gy1g57h4j42ppj30u00u00vy.jpg", "006tNc79gy1g57hfrnhe6j30u00w01eu.jpg"]) 155 | } 156 | 157 | } 158 | 159 | 160 | extension ViewController { 161 | 162 | // MARK: - 无缓存版本 163 | func setUpNoCache() { 164 | 165 | NoCacheAvatarManager.groupAvatarType = .QQ 166 | NoCacheAvatarManager.distanceBetweenAvatar = 1 167 | 168 | /// ImageView 169 | ncImageViewW1.setNoCacheImageAvatar(groupId: "ncImageViewW1", groupSource: [UIImage(named: "noCache1")!]) 170 | ncImageViewW2.setNoCacheImageAvatar(groupId: "ncImageViewW2", groupSource: [UIImage(named: "noCache1")!, UIImage(named: "noCache2")!]) 171 | 172 | ncImageViewW3.setNoCacheImageAvatar(groupId: "ncImageViewW3", groupSource: [UIImage(named: "noCache1")!, UIImage(named: "noCache2")!, UIImage(named: "noCache3")!]) 173 | 174 | ncImageViewW4.setNoCacheImageAvatar(groupId: "ncImageViewW4", groupSource: [UIImage(named: "noCache1")!, UIImage(named: "noCache2")!, UIImage(named: "noCache3")!, UIImage(named: "noCache4")!], setImageHandler: { (img) in 175 | print(img) 176 | }) { (groupId, groupImage, itemImageArray, cacheId) in 177 | print(groupId, groupImage, itemImageArray, cacheId) 178 | } 179 | 180 | ncImageViewW5.setNoCacheImageAvatar(groupId: "ncImageViewW5", groupSource: [UIImage(named: "noCache1")!, UIImage(named: "noCache2")!, UIImage(named: "noCache3")!, UIImage(named: "noCache1")!, UIImage(named: "noCache2")!]) 181 | 182 | ncImageViewW6.setNoCacheImageAvatar(groupId: "ncImageViewW6", groupSource: [UIImage(named: "noCache1")!, UIImage(named: "noCache2")!, UIImage(named: "noCache3")!, UIImage(named: "noCache1")!, UIImage(named: "noCache2")!, UIImage(named: "noCache3")!, UIImage(named: "noCache3")!]) 183 | 184 | 185 | /// Button 186 | avaButton.setNoCacheImageAvatar(groupId: "ncImageViewW6", groupSource: [UIImage(named: "noCache1")!, UIImage(named: "noCache2")!, UIImage(named: "noCache3")!, UIImage(named: "noCache4")!, UIImage(named: "noCache2")!, UIImage(named: "noCache1")!, UIImage(named: "noCache2")!, UIImage(named: "noCache1")!], state: .normal, setImageHandler: { (img) in 187 | print(img) 188 | }) { (groupId, groupImage, itemImageArray, cacheId) in 189 | print(groupId, groupImage, itemImageArray, cacheId) 190 | } 191 | 192 | avaBgButton.setNoCacheImageAvatar(groupId: "ncImageViewW6", groupSource: [UIImage(named: "noCache1")!, UIImage(named: "noCache2")!, UIImage(named: "noCache3")!, UIImage(named: "noCache1")!, UIImage(named: "noCache2")!, UIImage(named: "noCache1")!, UIImage(named: "noCache4")!, UIImage(named: "noCache1")!, UIImage(named: "noCache2")!], state: .normal) 193 | } 194 | } 195 | 196 | 197 | 198 | extension ViewController { 199 | 200 | 201 | // MARK: - tableView测试 202 | @objc func goToTest() { 203 | 204 | navigationController?.pushViewController(TestViewController(), animated: true) 205 | } 206 | 207 | // MARK: - 清理缓存 208 | @objc func clean() { 209 | 210 | ImageCache.default.clearDiskCache() 211 | ImageCache.default.clearMemoryCache() 212 | ImageCache.default.cleanExpiredDiskCache { [weak self] in 213 | guard let self = self else { return } 214 | self.setUpLoadData() 215 | } 216 | } 217 | } 218 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /CDDGroupAvatarSwift/Avatar/AvatarHelper.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AvatarHelper.swift 3 | // CDDGroupAvatarSwift 4 | // 5 | // Created by 陈甸甸 on 2020/3/9. 6 | // Copyright © 2020 RocketsChen. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import CommonCrypto 11 | 12 | 13 | 14 | struct AvatarHelper { 15 | 16 | // MARK: - 获取群头像最大数组数量 17 | public static func getTypefMaxCount(_ groupSource: [T], _ groupAvatarType: DCGroupAvatarType) -> [T] { 18 | 19 | var newSource = [T]() 20 | var count: Int 21 | switch groupAvatarType { 22 | 23 | case .WeChat: 24 | count = AvatarConfig.DCMaxWeChatCount 25 | 26 | case .QQ: 27 | count = AvatarConfig.DCMaxQQCount 28 | 29 | case .WeiBo: 30 | count = AvatarConfig.DCMaxWeiBoCount 31 | } 32 | 33 | for i in 0.. CGSize { 46 | 47 | var avatarSize: CGSize = CGSize.zero 48 | let wholeSize = containerSize 49 | 50 | if groupCount == DCNumberOfGroupAvatarType.One.description() { 51 | avatarSize = wholeSize 52 | 53 | }else if groupCount == DCNumberOfGroupAvatarType.Two.description() { 54 | avatarSize = CGSize(width: (wholeSize.width - distance) / 2, height: wholeSize.height) 55 | 56 | }else if groupCount == DCNumberOfGroupAvatarType.Three.description() , index == 0 { 57 | avatarSize = CGSize(width: (wholeSize.width - distance) / 2, height: wholeSize.height) 58 | 59 | }else { 60 | avatarSize = CGSize(width: (wholeSize.width - distance) / 2, height: (wholeSize.height - distance) / 2) 61 | } 62 | 63 | return avatarSize 64 | } 65 | 66 | 67 | 68 | // MARK: - 计算Type_WeChat头像尺寸 69 | public static func calculateSizeWeChatAvatarGroup(_ groupCount: Int, _ containerSize: CGSize, _ distance: CGFloat) -> CGSize { 70 | 71 | var avatarSize: CGSize = CGSize.zero 72 | let wholeSize = containerSize 73 | 74 | if groupCount < DCNumberOfGroupAvatarType.Five.description() { 75 | 76 | avatarSize = CGSize(width: (wholeSize.width - (3 * distance)) / 2, height: (wholeSize.height - (3 * distance)) / 2) 77 | }else { 78 | 79 | avatarSize = CGSize(width: (wholeSize.width - (4 * distance)) / 3, height: (wholeSize.height - (4 * distance)) / 3) 80 | } 81 | 82 | return avatarSize 83 | } 84 | 85 | 86 | // MARK: - 计算TypeWeiBo头像尺寸 87 | public static func calculateRadiusWeiBoAvatarGroup(_ groupCount: Int, _ containerSize: CGSize, _ distance: CGFloat) -> CGFloat { 88 | 89 | let bigRadius: CGFloat = containerSize.width / 2 90 | var radius: CGFloat = 0 91 | 92 | switch groupCount { 93 | 94 | case DCNumberOfGroupAvatarType.One.description(): 95 | radius = bigRadius 96 | 97 | case DCNumberOfGroupAvatarType.Two.description(): 98 | radius = bigRadius / 2 + (distance / 2) 99 | 100 | case DCNumberOfGroupAvatarType.Three.description(): 101 | radius = (2 * sqrt(3) - 3) * bigRadius + (distance / 3) 102 | 103 | case DCNumberOfGroupAvatarType.Four.description(): 104 | radius = bigRadius / 2 - (distance / 2) 105 | 106 | default: 107 | radius = 0 108 | } 109 | 110 | return radius 111 | } 112 | 113 | 114 | // MARK: - 计算Type_WeiBo小头像位置 115 | public static func calculateWeiBoAvatarGroup(_ groupCount: Int, _ index: Int, _ containerSize: CGSize, _ distance: CGFloat) -> CGPoint { 116 | 117 | var avatarPoint = CGPoint.zero 118 | var avatarDiameter: CGFloat = calculateRadiusWeiBoAvatarGroup(groupCount, containerSize, distance) 119 | var radiusOffset: CGFloat = 0 120 | let bigRadius: CGFloat = containerSize.width / 2 121 | let shrinkage: CGFloat = groupCount == DCNumberOfGroupAvatarType.Four.description() ? distance : -2 * distance 122 | let indexFloat = CGFloat(index) 123 | let groupCountFloat = CGFloat(groupCount) 124 | let piFloat = CGFloat.pi 125 | 126 | if (groupCount == DCNumberOfGroupAvatarType.One.description()) { 127 | 128 | avatarPoint = CGPoint(x: containerSize.width * 0.5, y: containerSize.height * 0.5) 129 | 130 | } else if (groupCount == DCNumberOfGroupAvatarType.Three.description()) { 131 | 132 | let difference: CGFloat = (bigRadius - avatarDiameter) 133 | 134 | if (index == 1) { 135 | 136 | avatarDiameter = avatarDiameter - shrinkage 137 | avatarPoint = CGPoint(x: bigRadius, y: avatarDiameter + distance) 138 | 139 | }else{ 140 | 141 | avatarDiameter = avatarDiameter + shrinkage 142 | radiusOffset = indexFloat * -0.5 * piFloat 143 | let pX: CGFloat = avatarDiameter * CGFloat(cosf(Float(radiusOffset))) 144 | avatarPoint = CGPoint(x: bigRadius + pX, y: bigRadius + (difference / 2) + distance) 145 | } 146 | 147 | }else{ 148 | 149 | avatarDiameter = avatarDiameter + shrinkage 150 | radiusOffset = -0.75 * piFloat 151 | 152 | let content: Float = Float(2 * piFloat * indexFloat / groupCountFloat + radiusOffset) 153 | let pX: CGFloat = avatarDiameter * CGFloat(cosf(content)) 154 | let pY: CGFloat = avatarDiameter * CGFloat(sinf(content)) 155 | avatarPoint = CGPoint(x: bigRadius + pX, y: bigRadius + pY) 156 | } 157 | 158 | return avatarPoint 159 | } 160 | 161 | // MARK: - 计算Type_WeChat/QQ小头像位置 162 | public static func calculatePointAvatarGroup(_ groupCount: Int, _ index: Int, _ containerSize: CGSize, _ distance: CGFloat, _ avatarType: DCGroupAvatarType) -> CGPoint { 163 | 164 | var avatarPoint = CGPoint.zero 165 | 166 | let wcSize: CGSize = calculateSizeWeChatAvatarGroup(groupCount, containerSize, distance) 167 | let qqSize: CGSize = calculateSizeQQAvatarGroup(groupCount, index, containerSize, distance) 168 | let avatarSize: CGSize = (avatarType == .WeChat) ? wcSize : qqSize 169 | 170 | var currentIndex = index 171 | let avaWidth = avatarSize.width 172 | let avaHeight = avatarSize.height 173 | let currentIndexFloat = CGFloat(currentIndex) 174 | var row: CGFloat = 0 175 | var column: CGFloat = 0 176 | let maxWeiChatCount = CGFloat(AvatarConfig.DCMaxWeChatColumn) 177 | 178 | switch groupCount { 179 | case DCNumberOfGroupAvatarType.One.description(): 180 | if avatarType == .WeChat { 181 | avatarPoint = CGPoint(x: (containerSize.width - avaWidth) * 0.5, y: (containerSize.height - avaHeight) * 0.5) 182 | } 183 | case DCNumberOfGroupAvatarType.Two.description(): 184 | 185 | if avatarType == .WeChat { 186 | 187 | avatarPoint = CGPoint(x: currentIndexFloat * (avaWidth + distance) + distance, y: (containerSize.height - avaHeight) / 2) 188 | }else if avatarType == .QQ { 189 | 190 | avatarPoint = CGPoint(x: currentIndexFloat * (avaWidth + distance), y: 0) 191 | } 192 | 193 | case DCNumberOfGroupAvatarType.Three.description(): 194 | 195 | if avatarType == .WeChat { 196 | 197 | if currentIndex == 0 { 198 | avatarPoint = CGPoint(x: (containerSize.width - avaWidth) / 2, y: distance) 199 | }else { 200 | 201 | avatarPoint = CGPoint(x: (currentIndexFloat - 1) * (avaWidth + distance) + distance, y: avaHeight + 2 * distance) 202 | } 203 | 204 | }else if avatarType == .QQ { 205 | 206 | if currentIndex == 0 { 207 | avatarPoint = CGPoint(x: 0, y: 0); 208 | }else { 209 | if currentIndex == 2 { 210 | currentIndex = currentIndex + 1 211 | } 212 | column = CGFloat(currentIndex / 2) 213 | avatarPoint = CGPoint(x: avaWidth + distance, y: column * (avaHeight + distance)) 214 | } 215 | } 216 | 217 | case DCNumberOfGroupAvatarType.Four.description(): 218 | 219 | column = computing(currentIndexFloat, 2).column 220 | row = computing(currentIndexFloat, 2).row 221 | 222 | if avatarType == .WeChat { 223 | 224 | avatarPoint = CGPoint(x: row * (avaWidth + distance) + distance, y: column * (avaHeight + distance) + distance) 225 | 226 | }else if avatarType == .QQ { 227 | 228 | avatarPoint = CGPoint(x: row * (avaWidth + distance), y: column * (avaHeight + distance)) 229 | } 230 | 231 | case DCNumberOfGroupAvatarType.Five.description(): 232 | 233 | if avatarType == .WeChat { 234 | 235 | let tempPoint = CGPoint(x: (containerSize.width - distance - (2 * avaWidth)) / 2, y: (containerSize.height - distance - (2 * avaHeight)) / 2) 236 | if currentIndex <= 1 { 237 | avatarPoint = CGPoint(x: currentIndexFloat * (distance + avaWidth) + tempPoint.x , y: tempPoint.y) 238 | 239 | }else { 240 | avatarPoint = CGPoint(x: (currentIndexFloat - 2) * (avaWidth + distance) + distance, y: tempPoint.y + avaHeight + distance) 241 | } 242 | } 243 | 244 | case DCNumberOfGroupAvatarType.Six.description(): 245 | 246 | let tempPointY: CGFloat = (containerSize.height - distance - (2 * avaHeight)) / 2 247 | 248 | if avatarType == .WeChat { 249 | column = computing(currentIndexFloat, maxWeiChatCount).column 250 | row = computing(currentIndexFloat, maxWeiChatCount).row 251 | avatarPoint = CGPoint(x: row * (avaWidth + distance) + distance, y: column * (avaHeight + distance) + tempPointY) 252 | } 253 | 254 | case DCNumberOfGroupAvatarType.Seven.description(): 255 | if avatarType == .WeChat { 256 | 257 | if currentIndex == 0 { 258 | 259 | avatarPoint = CGPoint(x: (containerSize.width - avaWidth) / 2, y: distance) 260 | }else { 261 | 262 | column = computing(currentIndexFloat + 2, maxWeiChatCount).column 263 | row = computing(currentIndexFloat + 2, maxWeiChatCount).row 264 | avatarPoint = CGPoint(x: row * (avaWidth + distance) + distance, y: column * (avaHeight + distance) + distance) 265 | } 266 | } 267 | 268 | 269 | case DCNumberOfGroupAvatarType.Eight.description(): 270 | if avatarType == .WeChat { 271 | 272 | if currentIndex < 2 { 273 | let tempPointX = (containerSize.width - 2 * avaWidth - distance) / 2 274 | avatarPoint = CGPoint(x: currentIndexFloat * (avaWidth + distance) + tempPointX, y: distance) 275 | }else { 276 | column = computing(currentIndexFloat + 1, maxWeiChatCount).column 277 | row = computing(currentIndexFloat + 1, maxWeiChatCount).row 278 | avatarPoint = CGPoint(x: row * (avaWidth + distance) + distance, y: column * (avaHeight + distance) + distance) 279 | } 280 | } 281 | 282 | case DCNumberOfGroupAvatarType.Nine.description(): 283 | if avatarType == .WeChat { 284 | column = computing(currentIndexFloat, maxWeiChatCount).column 285 | row = computing(currentIndexFloat, maxWeiChatCount).row 286 | avatarPoint = CGPoint(x: row * (avaWidth + distance) + distance, y: column * (avaHeight + distance) + distance) 287 | } 288 | default: 289 | break 290 | } 291 | return avatarPoint 292 | } 293 | 294 | } 295 | 296 | 297 | extension AvatarHelperTool { 298 | 299 | // MARK: - 计算行和列 300 | private static func computing(_ current: CGFloat , _ operation: CGFloat) -> (column: CGFloat, row: CGFloat) { 301 | 302 | let columnInt = Int(current) / Int(operation) 303 | let rowInt = Int(current) % Int(operation) 304 | return(column: CGFloat(columnInt), row: CGFloat(rowInt)) 305 | } 306 | 307 | } 308 | 309 | 310 | 311 | extension String { 312 | 313 | public var md5: String? { 314 | 315 | let str = self.cString(using: String.Encoding.utf8) 316 | let strLen = CUnsignedInt(self.lengthOfBytes(using: String.Encoding.utf8)) 317 | let digestLen = Int(CC_MD5_DIGEST_LENGTH) 318 | let result = UnsafeMutablePointer.allocate(capacity: digestLen) 319 | CC_MD5(str!, strLen, result) 320 | let hash = NSMutableString() 321 | for i in 0 ..< digestLen { 322 | hash.appendFormat("%02x", result[i]) 323 | } 324 | free(result) 325 | return String(format: hash as String) 326 | } 327 | } 328 | 329 | 330 | 331 | extension UIColor { 332 | 333 | // MARK: - 颜色转字符串 334 | public var hexString: String? { 335 | var red: CGFloat = 0 336 | var green: CGFloat = 0 337 | var blue: CGFloat = 0 338 | var alpha: CGFloat = 0 339 | 340 | let multiplier = CGFloat(255.999999) 341 | 342 | guard self.getRed(&red, green: &green, blue: &blue, alpha: &alpha) else { 343 | return nil 344 | } 345 | 346 | if alpha == 1.0 { 347 | return String( 348 | format: "#%02lX%02lX%02lX", 349 | Int(red * multiplier), 350 | Int(green * multiplier), 351 | Int(blue * multiplier) 352 | ) 353 | } 354 | else { 355 | return String( 356 | format: "#%02lX%02lX%02lX%02lX", 357 | Int(red * multiplier), 358 | Int(green * multiplier), 359 | Int(blue * multiplier), 360 | Int(alpha * multiplier) 361 | ) 362 | } 363 | } 364 | } 365 | 366 | 367 | 368 | extension UIImage { 369 | 370 | // MARK: - 裁剪图片 371 | public func cutImageView(_ size: CGSize, _ rect: CGRect) -> UIImage { 372 | 373 | var clipImage: UIImage = self 374 | let scaleWidth: CGFloat = self.size.width / size.width 375 | let scaleHeight: CGFloat = self.size.height / size.height 376 | let clipRect = CGRect(x: rect.origin.x * scaleWidth, y: rect.origin.y * scaleHeight, width: rect.size.width * scaleWidth, height: rect.size.height * scaleHeight) 377 | 378 | UIGraphicsBeginImageContext(clipRect.size) 379 | clipImage.draw(at: CGPoint(x: -clipRect.origin.x, y: -clipRect.origin.y)) 380 | clipImage = UIGraphicsGetImageFromCurrentImageContext()! 381 | UIGraphicsEndImageContext() 382 | 383 | return clipImage 384 | 385 | } 386 | 387 | 388 | // MARK: - 画圆 389 | public func cgContextAddArcToPointImage(_ borderWidth: CGFloat, _ borderColor: UIColor) -> UIImage { 390 | 391 | var avatarImage: UIImage = self 392 | let size: CGSize = CGSize(width: avatarImage.size.width + 2 * borderWidth, height: avatarImage.size.height + 2 * borderWidth) 393 | UIGraphicsBeginImageContextWithOptions(size, false, 0) 394 | var path = UIBezierPath(ovalIn: CGRect(x: 0, y: 0, width: size.width, height: size.height)) 395 | borderColor.set() 396 | path.fill() 397 | path = UIBezierPath(ovalIn: CGRect(x: borderWidth, y: borderWidth, width: avatarImage.size.width, height: avatarImage.size.height)) 398 | path.addClip() 399 | avatarImage.draw(in: CGRect(x: borderWidth, y: borderWidth, width: avatarImage.size.width, height: avatarImage.size.height)) 400 | avatarImage = UIGraphicsGetImageFromCurrentImageContext()! 401 | UIGraphicsEndImageContext() 402 | 403 | return avatarImage 404 | } 405 | 406 | 407 | // MARK: - 返回占位 408 | public func backItemPlaceholderImage(_ placeholder: [UIImage]? = nil, _ groupCount: Int, _ groupIndex: Int) -> UIImage{ 409 | 410 | var itemPlaceholder = self 411 | guard let placeholderArray = placeholder else { 412 | return itemPlaceholder 413 | } 414 | 415 | if placeholderArray.count > 0 && placeholderArray.count >= groupCount { 416 | let item = placeholderArray[groupIndex] 417 | itemPlaceholder = item 418 | } 419 | return itemPlaceholder 420 | } 421 | 422 | } 423 | -------------------------------------------------------------------------------- /Demo/CDDGroupAvatarSwift/CDDGroupAvatarSwift.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 50; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 73D461603818EE0C8A81A817 /* libPods-CDDGroupAvatarSwift.a in Frameworks */ = {isa = PBXBuildFile; fileRef = D044FC243C85E60DD1A3EAD0 /* libPods-CDDGroupAvatarSwift.a */; }; 11 | 9C172AAA2430CD3A00A7D3E0 /* UIImage+NoCacheGroup.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9C172A9D2430CD3A00A7D3E0 /* UIImage+NoCacheGroup.swift */; }; 12 | 9C172AAB2430CD3A00A7D3E0 /* NoCacheAvatarManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9C172A9E2430CD3A00A7D3E0 /* NoCacheAvatarManager.swift */; }; 13 | 9C172AAC2430CD3A00A7D3E0 /* UIButton+NoCacheGroup.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9C172A9F2430CD3A00A7D3E0 /* UIButton+NoCacheGroup.swift */; }; 14 | 9C172AAD2430CD3A00A7D3E0 /* UIImageView+NoCacheGroup.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9C172AA02430CD3A00A7D3E0 /* UIImageView+NoCacheGroup.swift */; }; 15 | 9C172AAE2430CD3A00A7D3E0 /* UIImageView+Group.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9C172AA22430CD3A00A7D3E0 /* UIImageView+Group.swift */; }; 16 | 9C172AAF2430CD3A00A7D3E0 /* CacheAvatarHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9C172AA32430CD3A00A7D3E0 /* CacheAvatarHelper.swift */; }; 17 | 9C172AB02430CD3A00A7D3E0 /* UIButton+Group.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9C172AA42430CD3A00A7D3E0 /* UIButton+Group.swift */; }; 18 | 9C172AB12430CD3A00A7D3E0 /* UIImage+Group.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9C172AA52430CD3A00A7D3E0 /* UIImage+Group.swift */; }; 19 | 9C172AB22430CD3A00A7D3E0 /* AvatarManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9C172AA62430CD3A00A7D3E0 /* AvatarManager.swift */; }; 20 | 9C172AB32430CD3A00A7D3E0 /* AvatarHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9C172AA82430CD3A00A7D3E0 /* AvatarHelper.swift */; }; 21 | 9C172AB42430CD3A00A7D3E0 /* AvatarConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9C172AA92430CD3A00A7D3E0 /* AvatarConfig.swift */; }; 22 | 9CB957AA241F2EC000784FA4 /* KMCGeigerCounterTick.aiff in Resources */ = {isa = PBXBuildFile; fileRef = 9CB957A7241F2EC000784FA4 /* KMCGeigerCounterTick.aiff */; }; 23 | 9CB957AB241F2EC000784FA4 /* KMCGeigerCounter.m in Sources */ = {isa = PBXBuildFile; fileRef = 9CB957A9241F2EC000784FA4 /* KMCGeigerCounter.m */; }; 24 | 9CCFC5D0241506690032F6DF /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9CCFC5CF241506690032F6DF /* AppDelegate.swift */; }; 25 | 9CCFC5D4241506690032F6DF /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9CCFC5D3241506690032F6DF /* ViewController.swift */; }; 26 | 9CCFC5D7241506690032F6DF /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9CCFC5D5241506690032F6DF /* Main.storyboard */; }; 27 | 9CCFC5D9241506690032F6DF /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 9CCFC5D8241506690032F6DF /* Assets.xcassets */; }; 28 | 9CCFC5DC241506690032F6DF /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9CCFC5DA241506690032F6DF /* LaunchScreen.storyboard */; }; 29 | 9CCFC5E824154AE20032F6DF /* TestViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9CCFC5E724154AE20032F6DF /* TestViewController.swift */; }; 30 | /* End PBXBuildFile section */ 31 | 32 | /* Begin PBXFileReference section */ 33 | 74FC7A07B969247A327C0E75 /* Pods-CDDGroupAvatarSwift.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CDDGroupAvatarSwift.debug.xcconfig"; path = "Target Support Files/Pods-CDDGroupAvatarSwift/Pods-CDDGroupAvatarSwift.debug.xcconfig"; sourceTree = ""; }; 34 | 7E1ECD12E663522FE3602BF1 /* Pods-CDDGroupAvatarSwift.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CDDGroupAvatarSwift.release.xcconfig"; path = "Target Support Files/Pods-CDDGroupAvatarSwift/Pods-CDDGroupAvatarSwift.release.xcconfig"; sourceTree = ""; }; 35 | 9C172A9D2430CD3A00A7D3E0 /* UIImage+NoCacheGroup.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIImage+NoCacheGroup.swift"; sourceTree = ""; }; 36 | 9C172A9E2430CD3A00A7D3E0 /* NoCacheAvatarManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NoCacheAvatarManager.swift; sourceTree = ""; }; 37 | 9C172A9F2430CD3A00A7D3E0 /* UIButton+NoCacheGroup.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIButton+NoCacheGroup.swift"; sourceTree = ""; }; 38 | 9C172AA02430CD3A00A7D3E0 /* UIImageView+NoCacheGroup.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIImageView+NoCacheGroup.swift"; sourceTree = ""; }; 39 | 9C172AA22430CD3A00A7D3E0 /* UIImageView+Group.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIImageView+Group.swift"; sourceTree = ""; }; 40 | 9C172AA32430CD3A00A7D3E0 /* CacheAvatarHelper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CacheAvatarHelper.swift; sourceTree = ""; }; 41 | 9C172AA42430CD3A00A7D3E0 /* UIButton+Group.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIButton+Group.swift"; sourceTree = ""; }; 42 | 9C172AA52430CD3A00A7D3E0 /* UIImage+Group.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIImage+Group.swift"; sourceTree = ""; }; 43 | 9C172AA62430CD3A00A7D3E0 /* AvatarManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AvatarManager.swift; sourceTree = ""; }; 44 | 9C172AA82430CD3A00A7D3E0 /* AvatarHelper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AvatarHelper.swift; sourceTree = ""; }; 45 | 9C172AA92430CD3A00A7D3E0 /* AvatarConfig.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AvatarConfig.swift; sourceTree = ""; }; 46 | 9CB957A7241F2EC000784FA4 /* KMCGeigerCounterTick.aiff */ = {isa = PBXFileReference; lastKnownFileType = audio.aiff; path = KMCGeigerCounterTick.aiff; sourceTree = ""; }; 47 | 9CB957A8241F2EC000784FA4 /* KMCGeigerCounter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KMCGeigerCounter.h; sourceTree = ""; }; 48 | 9CB957A9241F2EC000784FA4 /* KMCGeigerCounter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KMCGeigerCounter.m; sourceTree = ""; }; 49 | 9CB957B2241F2FDB00784FA4 /* CDDGroupAvatarSwift-Bridging-Header.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "CDDGroupAvatarSwift-Bridging-Header.h"; sourceTree = ""; }; 50 | 9CCFC5CC241506680032F6DF /* CDDGroupAvatarSwift.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CDDGroupAvatarSwift.app; sourceTree = BUILT_PRODUCTS_DIR; }; 51 | 9CCFC5CF241506690032F6DF /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 52 | 9CCFC5D3241506690032F6DF /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 53 | 9CCFC5D6241506690032F6DF /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 54 | 9CCFC5D8241506690032F6DF /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 55 | 9CCFC5DB241506690032F6DF /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 56 | 9CCFC5DD241506690032F6DF /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 57 | 9CCFC5E724154AE20032F6DF /* TestViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestViewController.swift; sourceTree = ""; }; 58 | D044FC243C85E60DD1A3EAD0 /* libPods-CDDGroupAvatarSwift.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-CDDGroupAvatarSwift.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 59 | /* End PBXFileReference section */ 60 | 61 | /* Begin PBXFrameworksBuildPhase section */ 62 | 9CCFC5C9241506680032F6DF /* Frameworks */ = { 63 | isa = PBXFrameworksBuildPhase; 64 | buildActionMask = 2147483647; 65 | files = ( 66 | 73D461603818EE0C8A81A817 /* libPods-CDDGroupAvatarSwift.a in Frameworks */, 67 | ); 68 | runOnlyForDeploymentPostprocessing = 0; 69 | }; 70 | /* End PBXFrameworksBuildPhase section */ 71 | 72 | /* Begin PBXGroup section */ 73 | 6805D0A76193373D3F6E528C /* Frameworks */ = { 74 | isa = PBXGroup; 75 | children = ( 76 | D044FC243C85E60DD1A3EAD0 /* libPods-CDDGroupAvatarSwift.a */, 77 | ); 78 | name = Frameworks; 79 | sourceTree = ""; 80 | }; 81 | 90BE9B1E7943853A5FD6C452 /* Pods */ = { 82 | isa = PBXGroup; 83 | children = ( 84 | 74FC7A07B969247A327C0E75 /* Pods-CDDGroupAvatarSwift.debug.xcconfig */, 85 | 7E1ECD12E663522FE3602BF1 /* Pods-CDDGroupAvatarSwift.release.xcconfig */, 86 | ); 87 | path = Pods; 88 | sourceTree = ""; 89 | }; 90 | 9C172A9B2430CD3A00A7D3E0 /* CDDGroupAvatarSwift */ = { 91 | isa = PBXGroup; 92 | children = ( 93 | 9C172A9C2430CD3A00A7D3E0 /* NoCacheGroupAvatar */, 94 | 9C172AA12430CD3A00A7D3E0 /* CacheGroupAvatar */, 95 | 9C172AA72430CD3A00A7D3E0 /* Avatar */, 96 | ); 97 | name = CDDGroupAvatarSwift; 98 | path = ../../../CDDGroupAvatarSwift; 99 | sourceTree = ""; 100 | }; 101 | 9C172A9C2430CD3A00A7D3E0 /* NoCacheGroupAvatar */ = { 102 | isa = PBXGroup; 103 | children = ( 104 | 9C172A9D2430CD3A00A7D3E0 /* UIImage+NoCacheGroup.swift */, 105 | 9C172A9E2430CD3A00A7D3E0 /* NoCacheAvatarManager.swift */, 106 | 9C172A9F2430CD3A00A7D3E0 /* UIButton+NoCacheGroup.swift */, 107 | 9C172AA02430CD3A00A7D3E0 /* UIImageView+NoCacheGroup.swift */, 108 | ); 109 | path = NoCacheGroupAvatar; 110 | sourceTree = ""; 111 | }; 112 | 9C172AA12430CD3A00A7D3E0 /* CacheGroupAvatar */ = { 113 | isa = PBXGroup; 114 | children = ( 115 | 9C172AA22430CD3A00A7D3E0 /* UIImageView+Group.swift */, 116 | 9C172AA32430CD3A00A7D3E0 /* CacheAvatarHelper.swift */, 117 | 9C172AA42430CD3A00A7D3E0 /* UIButton+Group.swift */, 118 | 9C172AA52430CD3A00A7D3E0 /* UIImage+Group.swift */, 119 | 9C172AA62430CD3A00A7D3E0 /* AvatarManager.swift */, 120 | ); 121 | path = CacheGroupAvatar; 122 | sourceTree = ""; 123 | }; 124 | 9C172AA72430CD3A00A7D3E0 /* Avatar */ = { 125 | isa = PBXGroup; 126 | children = ( 127 | 9C172AA82430CD3A00A7D3E0 /* AvatarHelper.swift */, 128 | 9C172AA92430CD3A00A7D3E0 /* AvatarConfig.swift */, 129 | ); 130 | path = Avatar; 131 | sourceTree = ""; 132 | }; 133 | 9CB957A5241F2EC000784FA4 /* PFS */ = { 134 | isa = PBXGroup; 135 | children = ( 136 | 9CB957A6241F2EC000784FA4 /* KMCGeigerCounter */, 137 | ); 138 | path = PFS; 139 | sourceTree = ""; 140 | }; 141 | 9CB957A6241F2EC000784FA4 /* KMCGeigerCounter */ = { 142 | isa = PBXGroup; 143 | children = ( 144 | 9CB957A7241F2EC000784FA4 /* KMCGeigerCounterTick.aiff */, 145 | 9CB957A8241F2EC000784FA4 /* KMCGeigerCounter.h */, 146 | 9CB957A9241F2EC000784FA4 /* KMCGeigerCounter.m */, 147 | ); 148 | path = KMCGeigerCounter; 149 | sourceTree = ""; 150 | }; 151 | 9CCFC5C3241506680032F6DF = { 152 | isa = PBXGroup; 153 | children = ( 154 | 9CCFC5CE241506680032F6DF /* CDDGroupAvatarSwift */, 155 | 9CCFC5CD241506680032F6DF /* Products */, 156 | 90BE9B1E7943853A5FD6C452 /* Pods */, 157 | 6805D0A76193373D3F6E528C /* Frameworks */, 158 | ); 159 | sourceTree = ""; 160 | }; 161 | 9CCFC5CD241506680032F6DF /* Products */ = { 162 | isa = PBXGroup; 163 | children = ( 164 | 9CCFC5CC241506680032F6DF /* CDDGroupAvatarSwift.app */, 165 | ); 166 | name = Products; 167 | sourceTree = ""; 168 | }; 169 | 9CCFC5CE241506680032F6DF /* CDDGroupAvatarSwift */ = { 170 | isa = PBXGroup; 171 | children = ( 172 | 9CB957B2241F2FDB00784FA4 /* CDDGroupAvatarSwift-Bridging-Header.h */, 173 | 9C172A9B2430CD3A00A7D3E0 /* CDDGroupAvatarSwift */, 174 | 9CB957A5241F2EC000784FA4 /* PFS */, 175 | 9CCFC5CF241506690032F6DF /* AppDelegate.swift */, 176 | 9CCFC5D3241506690032F6DF /* ViewController.swift */, 177 | 9CCFC5E724154AE20032F6DF /* TestViewController.swift */, 178 | 9CCFC5D5241506690032F6DF /* Main.storyboard */, 179 | 9CCFC5D8241506690032F6DF /* Assets.xcassets */, 180 | 9CCFC5DA241506690032F6DF /* LaunchScreen.storyboard */, 181 | 9CCFC5DD241506690032F6DF /* Info.plist */, 182 | ); 183 | path = CDDGroupAvatarSwift; 184 | sourceTree = ""; 185 | }; 186 | /* End PBXGroup section */ 187 | 188 | /* Begin PBXNativeTarget section */ 189 | 9CCFC5CB241506680032F6DF /* CDDGroupAvatarSwift */ = { 190 | isa = PBXNativeTarget; 191 | buildConfigurationList = 9CCFC5E0241506690032F6DF /* Build configuration list for PBXNativeTarget "CDDGroupAvatarSwift" */; 192 | buildPhases = ( 193 | B272CDF86EF1073BF3470A68 /* [CP] Check Pods Manifest.lock */, 194 | 9CCFC5C8241506680032F6DF /* Sources */, 195 | 9CCFC5C9241506680032F6DF /* Frameworks */, 196 | 9CCFC5CA241506680032F6DF /* Resources */, 197 | ); 198 | buildRules = ( 199 | ); 200 | dependencies = ( 201 | ); 202 | name = CDDGroupAvatarSwift; 203 | productName = CDDGroupAvatarSwift; 204 | productReference = 9CCFC5CC241506680032F6DF /* CDDGroupAvatarSwift.app */; 205 | productType = "com.apple.product-type.application"; 206 | }; 207 | /* End PBXNativeTarget section */ 208 | 209 | /* Begin PBXProject section */ 210 | 9CCFC5C4241506680032F6DF /* Project object */ = { 211 | isa = PBXProject; 212 | attributes = { 213 | LastSwiftUpdateCheck = 1130; 214 | LastUpgradeCheck = 1130; 215 | ORGANIZATIONNAME = RocketsChen; 216 | TargetAttributes = { 217 | 9CCFC5CB241506680032F6DF = { 218 | CreatedOnToolsVersion = 11.3.1; 219 | }; 220 | }; 221 | }; 222 | buildConfigurationList = 9CCFC5C7241506680032F6DF /* Build configuration list for PBXProject "CDDGroupAvatarSwift" */; 223 | compatibilityVersion = "Xcode 9.3"; 224 | developmentRegion = en; 225 | hasScannedForEncodings = 0; 226 | knownRegions = ( 227 | en, 228 | Base, 229 | ); 230 | mainGroup = 9CCFC5C3241506680032F6DF; 231 | productRefGroup = 9CCFC5CD241506680032F6DF /* Products */; 232 | projectDirPath = ""; 233 | projectRoot = ""; 234 | targets = ( 235 | 9CCFC5CB241506680032F6DF /* CDDGroupAvatarSwift */, 236 | ); 237 | }; 238 | /* End PBXProject section */ 239 | 240 | /* Begin PBXResourcesBuildPhase section */ 241 | 9CCFC5CA241506680032F6DF /* Resources */ = { 242 | isa = PBXResourcesBuildPhase; 243 | buildActionMask = 2147483647; 244 | files = ( 245 | 9CCFC5DC241506690032F6DF /* LaunchScreen.storyboard in Resources */, 246 | 9CCFC5D9241506690032F6DF /* Assets.xcassets in Resources */, 247 | 9CB957AA241F2EC000784FA4 /* KMCGeigerCounterTick.aiff in Resources */, 248 | 9CCFC5D7241506690032F6DF /* Main.storyboard in Resources */, 249 | ); 250 | runOnlyForDeploymentPostprocessing = 0; 251 | }; 252 | /* End PBXResourcesBuildPhase section */ 253 | 254 | /* Begin PBXShellScriptBuildPhase section */ 255 | B272CDF86EF1073BF3470A68 /* [CP] Check Pods Manifest.lock */ = { 256 | isa = PBXShellScriptBuildPhase; 257 | buildActionMask = 2147483647; 258 | files = ( 259 | ); 260 | inputFileListPaths = ( 261 | ); 262 | inputPaths = ( 263 | "${PODS_PODFILE_DIR_PATH}/Podfile.lock", 264 | "${PODS_ROOT}/Manifest.lock", 265 | ); 266 | name = "[CP] Check Pods Manifest.lock"; 267 | outputFileListPaths = ( 268 | ); 269 | outputPaths = ( 270 | "$(DERIVED_FILE_DIR)/Pods-CDDGroupAvatarSwift-checkManifestLockResult.txt", 271 | ); 272 | runOnlyForDeploymentPostprocessing = 0; 273 | shellPath = /bin/sh; 274 | shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; 275 | showEnvVarsInLog = 0; 276 | }; 277 | /* End PBXShellScriptBuildPhase section */ 278 | 279 | /* Begin PBXSourcesBuildPhase section */ 280 | 9CCFC5C8241506680032F6DF /* Sources */ = { 281 | isa = PBXSourcesBuildPhase; 282 | buildActionMask = 2147483647; 283 | files = ( 284 | 9C172AAA2430CD3A00A7D3E0 /* UIImage+NoCacheGroup.swift in Sources */, 285 | 9CCFC5D4241506690032F6DF /* ViewController.swift in Sources */, 286 | 9C172AAB2430CD3A00A7D3E0 /* NoCacheAvatarManager.swift in Sources */, 287 | 9C172AB12430CD3A00A7D3E0 /* UIImage+Group.swift in Sources */, 288 | 9C172AB42430CD3A00A7D3E0 /* AvatarConfig.swift in Sources */, 289 | 9C172AB32430CD3A00A7D3E0 /* AvatarHelper.swift in Sources */, 290 | 9CCFC5E824154AE20032F6DF /* TestViewController.swift in Sources */, 291 | 9C172AB22430CD3A00A7D3E0 /* AvatarManager.swift in Sources */, 292 | 9CCFC5D0241506690032F6DF /* AppDelegate.swift in Sources */, 293 | 9C172AAC2430CD3A00A7D3E0 /* UIButton+NoCacheGroup.swift in Sources */, 294 | 9C172AAD2430CD3A00A7D3E0 /* UIImageView+NoCacheGroup.swift in Sources */, 295 | 9C172AB02430CD3A00A7D3E0 /* UIButton+Group.swift in Sources */, 296 | 9CB957AB241F2EC000784FA4 /* KMCGeigerCounter.m in Sources */, 297 | 9C172AAE2430CD3A00A7D3E0 /* UIImageView+Group.swift in Sources */, 298 | 9C172AAF2430CD3A00A7D3E0 /* CacheAvatarHelper.swift in Sources */, 299 | ); 300 | runOnlyForDeploymentPostprocessing = 0; 301 | }; 302 | /* End PBXSourcesBuildPhase section */ 303 | 304 | /* Begin PBXVariantGroup section */ 305 | 9CCFC5D5241506690032F6DF /* Main.storyboard */ = { 306 | isa = PBXVariantGroup; 307 | children = ( 308 | 9CCFC5D6241506690032F6DF /* Base */, 309 | ); 310 | name = Main.storyboard; 311 | sourceTree = ""; 312 | }; 313 | 9CCFC5DA241506690032F6DF /* LaunchScreen.storyboard */ = { 314 | isa = PBXVariantGroup; 315 | children = ( 316 | 9CCFC5DB241506690032F6DF /* Base */, 317 | ); 318 | name = LaunchScreen.storyboard; 319 | sourceTree = ""; 320 | }; 321 | /* End PBXVariantGroup section */ 322 | 323 | /* Begin XCBuildConfiguration section */ 324 | 9CCFC5DE241506690032F6DF /* Debug */ = { 325 | isa = XCBuildConfiguration; 326 | buildSettings = { 327 | ALWAYS_SEARCH_USER_PATHS = NO; 328 | CLANG_ANALYZER_NONNULL = YES; 329 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 330 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 331 | CLANG_CXX_LIBRARY = "libc++"; 332 | CLANG_ENABLE_MODULES = YES; 333 | CLANG_ENABLE_OBJC_ARC = YES; 334 | CLANG_ENABLE_OBJC_WEAK = YES; 335 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 336 | CLANG_WARN_BOOL_CONVERSION = YES; 337 | CLANG_WARN_COMMA = YES; 338 | CLANG_WARN_CONSTANT_CONVERSION = YES; 339 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 340 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 341 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 342 | CLANG_WARN_EMPTY_BODY = YES; 343 | CLANG_WARN_ENUM_CONVERSION = YES; 344 | CLANG_WARN_INFINITE_RECURSION = YES; 345 | CLANG_WARN_INT_CONVERSION = YES; 346 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 347 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 348 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 349 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 350 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 351 | CLANG_WARN_STRICT_PROTOTYPES = YES; 352 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 353 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 354 | CLANG_WARN_UNREACHABLE_CODE = YES; 355 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 356 | COPY_PHASE_STRIP = NO; 357 | DEBUG_INFORMATION_FORMAT = dwarf; 358 | ENABLE_STRICT_OBJC_MSGSEND = YES; 359 | ENABLE_TESTABILITY = YES; 360 | GCC_C_LANGUAGE_STANDARD = gnu11; 361 | GCC_DYNAMIC_NO_PIC = NO; 362 | GCC_NO_COMMON_BLOCKS = YES; 363 | GCC_OPTIMIZATION_LEVEL = 0; 364 | GCC_PREPROCESSOR_DEFINITIONS = ( 365 | "DEBUG=1", 366 | "$(inherited)", 367 | ); 368 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 369 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 370 | GCC_WARN_UNDECLARED_SELECTOR = YES; 371 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 372 | GCC_WARN_UNUSED_FUNCTION = YES; 373 | GCC_WARN_UNUSED_VARIABLE = YES; 374 | IPHONEOS_DEPLOYMENT_TARGET = 13.2; 375 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 376 | MTL_FAST_MATH = YES; 377 | ONLY_ACTIVE_ARCH = YES; 378 | SDKROOT = iphoneos; 379 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 380 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 381 | }; 382 | name = Debug; 383 | }; 384 | 9CCFC5DF241506690032F6DF /* Release */ = { 385 | isa = XCBuildConfiguration; 386 | buildSettings = { 387 | ALWAYS_SEARCH_USER_PATHS = NO; 388 | CLANG_ANALYZER_NONNULL = YES; 389 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 390 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 391 | CLANG_CXX_LIBRARY = "libc++"; 392 | CLANG_ENABLE_MODULES = YES; 393 | CLANG_ENABLE_OBJC_ARC = YES; 394 | CLANG_ENABLE_OBJC_WEAK = YES; 395 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 396 | CLANG_WARN_BOOL_CONVERSION = YES; 397 | CLANG_WARN_COMMA = YES; 398 | CLANG_WARN_CONSTANT_CONVERSION = YES; 399 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 400 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 401 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 402 | CLANG_WARN_EMPTY_BODY = YES; 403 | CLANG_WARN_ENUM_CONVERSION = YES; 404 | CLANG_WARN_INFINITE_RECURSION = YES; 405 | CLANG_WARN_INT_CONVERSION = YES; 406 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 407 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 408 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 409 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 410 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 411 | CLANG_WARN_STRICT_PROTOTYPES = YES; 412 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 413 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 414 | CLANG_WARN_UNREACHABLE_CODE = YES; 415 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 416 | COPY_PHASE_STRIP = NO; 417 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 418 | ENABLE_NS_ASSERTIONS = NO; 419 | ENABLE_STRICT_OBJC_MSGSEND = YES; 420 | GCC_C_LANGUAGE_STANDARD = gnu11; 421 | GCC_NO_COMMON_BLOCKS = YES; 422 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 423 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 424 | GCC_WARN_UNDECLARED_SELECTOR = YES; 425 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 426 | GCC_WARN_UNUSED_FUNCTION = YES; 427 | GCC_WARN_UNUSED_VARIABLE = YES; 428 | IPHONEOS_DEPLOYMENT_TARGET = 13.2; 429 | MTL_ENABLE_DEBUG_INFO = NO; 430 | MTL_FAST_MATH = YES; 431 | SDKROOT = iphoneos; 432 | SWIFT_COMPILATION_MODE = wholemodule; 433 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 434 | VALIDATE_PRODUCT = YES; 435 | }; 436 | name = Release; 437 | }; 438 | 9CCFC5E1241506690032F6DF /* Debug */ = { 439 | isa = XCBuildConfiguration; 440 | baseConfigurationReference = 74FC7A07B969247A327C0E75 /* Pods-CDDGroupAvatarSwift.debug.xcconfig */; 441 | buildSettings = { 442 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 443 | CODE_SIGN_STYLE = Automatic; 444 | DEVELOPMENT_TEAM = U3QZXY69QQ; 445 | INFOPLIST_FILE = CDDGroupAvatarSwift/Info.plist; 446 | IPHONEOS_DEPLOYMENT_TARGET = 10.0; 447 | LD_RUNPATH_SEARCH_PATHS = ( 448 | "$(inherited)", 449 | "@executable_path/Frameworks", 450 | ); 451 | MARKETING_VERSION = 1.2.5; 452 | PRODUCT_BUNDLE_IDENTIFIER = com.cdd.CDDGroupAvatarSwift; 453 | PRODUCT_NAME = "$(TARGET_NAME)"; 454 | SWIFT_OBJC_BRIDGING_HEADER = "CDDGroupAvatarSwift/CDDGroupAvatarSwift-Bridging-Header.h"; 455 | SWIFT_VERSION = 5.0; 456 | TARGETED_DEVICE_FAMILY = "1,2"; 457 | }; 458 | name = Debug; 459 | }; 460 | 9CCFC5E2241506690032F6DF /* Release */ = { 461 | isa = XCBuildConfiguration; 462 | baseConfigurationReference = 7E1ECD12E663522FE3602BF1 /* Pods-CDDGroupAvatarSwift.release.xcconfig */; 463 | buildSettings = { 464 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 465 | CODE_SIGN_STYLE = Automatic; 466 | DEVELOPMENT_TEAM = U3QZXY69QQ; 467 | INFOPLIST_FILE = CDDGroupAvatarSwift/Info.plist; 468 | IPHONEOS_DEPLOYMENT_TARGET = 10.0; 469 | LD_RUNPATH_SEARCH_PATHS = ( 470 | "$(inherited)", 471 | "@executable_path/Frameworks", 472 | ); 473 | MARKETING_VERSION = 1.2.5; 474 | PRODUCT_BUNDLE_IDENTIFIER = com.cdd.CDDGroupAvatarSwift; 475 | PRODUCT_NAME = "$(TARGET_NAME)"; 476 | SWIFT_OBJC_BRIDGING_HEADER = "CDDGroupAvatarSwift/CDDGroupAvatarSwift-Bridging-Header.h"; 477 | SWIFT_VERSION = 5.0; 478 | TARGETED_DEVICE_FAMILY = "1,2"; 479 | }; 480 | name = Release; 481 | }; 482 | /* End XCBuildConfiguration section */ 483 | 484 | /* Begin XCConfigurationList section */ 485 | 9CCFC5C7241506680032F6DF /* Build configuration list for PBXProject "CDDGroupAvatarSwift" */ = { 486 | isa = XCConfigurationList; 487 | buildConfigurations = ( 488 | 9CCFC5DE241506690032F6DF /* Debug */, 489 | 9CCFC5DF241506690032F6DF /* Release */, 490 | ); 491 | defaultConfigurationIsVisible = 0; 492 | defaultConfigurationName = Release; 493 | }; 494 | 9CCFC5E0241506690032F6DF /* Build configuration list for PBXNativeTarget "CDDGroupAvatarSwift" */ = { 495 | isa = XCConfigurationList; 496 | buildConfigurations = ( 497 | 9CCFC5E1241506690032F6DF /* Debug */, 498 | 9CCFC5E2241506690032F6DF /* Release */, 499 | ); 500 | defaultConfigurationIsVisible = 0; 501 | defaultConfigurationName = Release; 502 | }; 503 | /* End XCConfigurationList section */ 504 | }; 505 | rootObject = 9CCFC5C4241506680032F6DF /* Project object */; 506 | } 507 | -------------------------------------------------------------------------------- /Demo/CDDGroupAvatarSwift/CDDGroupAvatarSwift/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 101 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | --------------------------------------------------------------------------------