|
@@ -9,7 +9,7 @@
|
|
|
import Foundation
|
|
|
|
|
|
/// 滑动方向
|
|
|
-public enum moveDirection {
|
|
|
+public enum moveDirection {
|
|
|
case moveDirectionNormal
|
|
|
case moveDirectionUp
|
|
|
case moveDirectionDown
|
|
@@ -20,48 +20,45 @@ public enum moveDirection {
|
|
|
public extension UIImage {
|
|
|
// 从BFframwork bundle 中取图片
|
|
|
static func mc_loadImage(_ imageName: String, from bundleName: String, in podName: String) -> UIImage? {
|
|
|
-
|
|
|
- var associateBundleURL = Bundle.main.url(forResource: "Frameworks", withExtension: nil)
|
|
|
- associateBundleURL = associateBundleURL?.appendingPathComponent(podName)
|
|
|
- associateBundleURL = associateBundleURL?.appendingPathExtension("framework")
|
|
|
-
|
|
|
-
|
|
|
- if associateBundleURL == nil {
|
|
|
+ var associateBundleURL = Bundle.main.url(forResource: "Frameworks", withExtension: nil)
|
|
|
+ associateBundleURL = associateBundleURL?.appendingPathComponent(podName)
|
|
|
+ associateBundleURL = associateBundleURL?.appendingPathExtension("framework")
|
|
|
+
|
|
|
+ if associateBundleURL == nil {
|
|
|
+ print("获取bundle失败")
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+
|
|
|
+ let associateBunle = Bundle(url: associateBundleURL!)
|
|
|
+ associateBundleURL = associateBunle?.url(forResource: bundleName, withExtension: "bundle")
|
|
|
+
|
|
|
+ if associateBundleURL != nil {
|
|
|
+ let bundle = Bundle(url: associateBundleURL!)
|
|
|
+ let scale = Int(UIScreen.main.scale)
|
|
|
+
|
|
|
+ // 适配2x还是3x图片
|
|
|
+ let name = imageName + "@" + String(scale) + "x"
|
|
|
+ let path = bundle?.path(forResource: name, ofType: "png")
|
|
|
+
|
|
|
+ if path == nil {
|
|
|
print("获取bundle失败")
|
|
|
return nil
|
|
|
}
|
|
|
-
|
|
|
- let associateBunle = Bundle.init(url: associateBundleURL!)
|
|
|
- associateBundleURL = associateBunle?.url(forResource: bundleName, withExtension: "bundle")
|
|
|
-
|
|
|
- if associateBundleURL != nil {
|
|
|
- let bundle = Bundle.init(url: associateBundleURL!)
|
|
|
- let scale = Int(UIScreen.main.scale)
|
|
|
-
|
|
|
- // 适配2x还是3x图片
|
|
|
- let name = imageName + "@" + String(scale) + "x"
|
|
|
- let path = bundle?.path(forResource: name, ofType: "png")
|
|
|
-
|
|
|
- if path == nil {
|
|
|
- print("获取bundle失败")
|
|
|
- return nil
|
|
|
- }
|
|
|
- let image1 = UIImage.init(contentsOfFile: path!)
|
|
|
- return image1
|
|
|
+ let image1 = UIImage(contentsOfFile: path!)
|
|
|
+ return image1
|
|
|
|
|
|
- } else {
|
|
|
- return nil
|
|
|
- }
|
|
|
+ } else {
|
|
|
+ return nil
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
+ }
|
|
|
+
|
|
|
func BF_Image(named: String) -> UIImage {
|
|
|
let image: UIImage = UIImage(named: named, in: Bundle().BF_mainbundle(), compatibleWith: nil) ?? UIImage()
|
|
|
return image
|
|
|
}
|
|
|
|
|
|
- class func moduleImage(named: String, moduleName: String,isAssets:Bool = true) -> UIImage? {
|
|
|
- let image: UIImage? = UIImage(named: named, in: Bundle.current(moduleName: moduleName,isAssets: isAssets), compatibleWith: nil)
|
|
|
+ class func moduleImage(named: String, moduleName: String, isAssets: Bool = true) -> UIImage? {
|
|
|
+ let image: UIImage? = UIImage(named: named, in: Bundle.current(moduleName: moduleName, isAssets: isAssets), compatibleWith: nil)
|
|
|
return image
|
|
|
}
|
|
|
|
|
@@ -167,9 +164,8 @@ public extension UIImage {
|
|
|
UIGraphicsEndImageContext()
|
|
|
return image
|
|
|
}
|
|
|
-
|
|
|
- func nx_scaleWithMaxLength(maxLength: CGFloat,completion: @escaping ( _ image: UIImage) -> Void) {
|
|
|
-
|
|
|
+
|
|
|
+ func nx_scaleWithMaxLength(maxLength: CGFloat, completion: @escaping (_ image: UIImage) -> Void) {
|
|
|
var maxWidth: CGFloat = maxLength
|
|
|
var maxHeight: CGFloat = maxLength
|
|
|
|
|
@@ -185,9 +181,9 @@ public extension UIImage {
|
|
|
maxWidth = size.width * imageScale
|
|
|
}
|
|
|
}
|
|
|
- self.processImage(image: self, size: CGSize(width: maxWidth, height: maxHeight)) { newImage in
|
|
|
+ processImage(image: self, size: CGSize(width: maxWidth, height: maxHeight)) { newImage in
|
|
|
completion(newImage)
|
|
|
- }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/// 按照最短边缩放 add by ak
|
|
@@ -216,8 +212,8 @@ public extension UIImage {
|
|
|
|
|
|
return self
|
|
|
}
|
|
|
-
|
|
|
- func processImage(image: UIImage, size: CGSize,completion: @escaping ( _ image: UIImage) -> Void) {
|
|
|
+
|
|
|
+ func processImage(image: UIImage, size: CGSize, completion: @escaping (_ image: UIImage) -> Void) {
|
|
|
DispatchQueue.global().async {
|
|
|
var width: CGFloat = CGFloat(image.cgImage?.width ?? 0)
|
|
|
var height: CGFloat = CGFloat(image.cgImage?.height ?? 0)
|
|
@@ -253,12 +249,11 @@ public extension UIImage {
|
|
|
|
|
|
// 从当前context中创建一个改变大小后的图片
|
|
|
let scaledImage: UIImage = UIGraphicsGetImageFromCurrentImageContext()!
|
|
|
-
|
|
|
+
|
|
|
// 使当前的context出堆栈
|
|
|
UIGraphicsEndImageContext()
|
|
|
completion(scaledImage)
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
/// 缩放到指定大小 add by ak
|
|
@@ -298,10 +293,10 @@ public extension UIImage {
|
|
|
|
|
|
// 从当前context中创建一个改变大小后的图片
|
|
|
let scaledImage: UIImage = UIGraphicsGetImageFromCurrentImageContext()!
|
|
|
-
|
|
|
+
|
|
|
// 使当前的context出堆栈
|
|
|
UIGraphicsEndImageContext()
|
|
|
-
|
|
|
+
|
|
|
// 返回新的改变大小后的图片
|
|
|
return scaledImage
|
|
|
}
|
|
@@ -347,13 +342,13 @@ public extension UIImage {
|
|
|
UIGraphicsEndImageContext()
|
|
|
return tintedImage
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/// 保存图片文件到指定目录, 如果目录已经存在会先删除老文件
|
|
|
/// - Parameters:
|
|
|
/// - currentImage: 图片数据
|
|
|
/// - persent: 质量
|
|
|
/// - outFilePath: 输出目录
|
|
|
- class func saveImage(currentImage: UIImage,outFilePath: String) {
|
|
|
+ class func saveImage(currentImage: UIImage, outFilePath: String) {
|
|
|
// 文件存在先删除老文件
|
|
|
if FileManager.default.fileExists(atPath: outFilePath) {
|
|
|
do {
|
|
@@ -362,13 +357,13 @@ public extension UIImage {
|
|
|
BFLog(message: "删除文件出错 == \(error) \(outFilePath)")
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
if let imageData = currentImage.pngData() {
|
|
|
try? imageData.write(to: URL(fileURLWithPath: outFilePath))
|
|
|
print("保存图片成功到:filePath=\(outFilePath)")
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
convenience init?(color: UIColor, size: CGSize = CGSize(width: 1, height: 1)) {
|
|
|
let rect = CGRect(origin: .zero, size: size)
|
|
|
UIGraphicsBeginImageContextWithOptions(rect.size, false, 0.0)
|
|
@@ -376,7 +371,7 @@ public extension UIImage {
|
|
|
UIRectFill(rect)
|
|
|
let image = UIGraphicsGetImageFromCurrentImageContext()
|
|
|
UIGraphicsEndImageContext()
|
|
|
-
|
|
|
+
|
|
|
guard let cgImage = image?.cgImage else { return nil }
|
|
|
self.init(cgImage: cgImage)
|
|
|
}
|