File browser, file manager UI, browser by list, browser by icon,文件浏览器, 列表样式, 图标样式
To run the example project, clone the repo, and run pod install
from the Example directory first.
- iOS 14.0+
- Swift 5.0+
- show files with list style
- show files with icon style
- dynamic switch style
- reload list with difference algorithm
SwiftyFileBrowser is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'SwiftyFileBrowser'
class FileObject: SFile {
convenience init(id: String, type: SFileType = .folder, name: String?, detail: String?) {
self.init()
self.identifier = id
self.fileName = name
self.detailText = detail
self.fileType = type
}
var identifier: String = ""
var filePath: String?
var fileName: String?
var detailText: String?
var fileType: SFileType = .unknow
var state: SFileState = .downloading(progress: 0.4)
var thumbnail: UIImage?
var appIcon: UIImage?
}
let sfbView = SwiftyFileBrowser.init(frame: UIScreen.main.bounds, type: .list)
sfbView.delegate = self
let files = [
FileObject.init(id: "111", type: .folder, name: "name111434534534534523423535436346awefasdfas", detail: "2021/09/11-asdgsfgfadsfadfadfasdfadfadfadfadf"),
FileObject.init(id: "222", name: "name222", detail: "2021/09/13"),
FileObject.init(id: "333", name: "name333", detail: "2021/09/14"),
FileObject.init(id: "444", type: .unknow, name: "name444", detail: "2021/09/14"),
FileObject.init(id: "555", name: "name555", detail: "2021/09/15"),
FileObject.init(id: "666", name: "name666", detail: "2021/09/16")
]
sfbView.reloadBrowser(files: files)
self.view.addSubview(sfbView!)
let copyEle = UIAction.init(title: "Copy", image: nil, identifier: UIAction.Identifier.init("LongPress-Copy"), discoverabilityTitle: nil, attributes: [], state: .off) { act in
print("LongPress copy event!,index: \(self.sfbView?.longPressIndex)")
// TODO: copy logic
}
let moveEle = UIAction.init(title: "Move", image: nil, identifier: UIAction.Identifier.init("LongPress-Move"), discoverabilityTitle: nil, attributes: [], state: .off) { act in
print("LongPress Move event!,index: \(self.sfbView?.longPressIndex)")
// TODO: Move logic
}
self.sfbView?.longPressMenuElements = [copyEle, moveEle]
Hansen, heshanzhang@outlook.com
SwiftyFileBrowser is available under the MIT license. See the LICENSE file for more info.