Parcourir la source

1.增加判断文件夹下是否有内容判断
2.增加 view 转 UIImage

100Years il y a 2 semaines
Parent
commit
89653a1387

+ 10 - 0
TSSmalCoacopods/Classes/Ex/UIView+Ex.swift

@@ -435,3 +435,13 @@ public extension UIView {
             .forEach { $0.removeFromSuperlayer() }
     }
 }
+public extension UIView {
+    func asImage(opaque: Bool = false) -> UIImage {
+        let format = UIGraphicsImageRendererFormat()
+        format.opaque = opaque
+        let renderer = UIGraphicsImageRenderer(bounds: bounds, format: format)
+        return renderer.image { _ in
+            drawHierarchy(in: bounds, afterScreenUpdates: true)
+        }
+    }
+}

+ 12 - 0
TSSmalCoacopods/Classes/Tool/TSFileManagerTool.swift

@@ -104,6 +104,18 @@ public class TSFileManagerTool {
         }
     }
 
+    public static func hasContents(atPath path: String) -> Bool {
+        let fileManager = FileManager.default
+        
+        do {
+            let contents = try fileManager.contentsOfDirectory(atPath: path)
+            return !contents.isEmpty
+        } catch {
+            print("检查目录内容失败: \(error.localizedDescription)")
+            return false
+        }
+    }
+    
     // MARK: - 文件操作方法
 
     /// 检查文件或文件夹是否存在