增加换肤功能
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
//
|
||||
// RoomFileBroswerCell.swift
|
||||
// DemoApp
|
||||
//
|
||||
// Created by CY zhao on 2023/7/4.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import UIKit
|
||||
|
||||
public let RoomFileBroswerCellHeight = 40.0
|
||||
|
||||
class RoomFileBroswerCell: UITableViewCell {
|
||||
lazy var titlelabel: UILabel = {
|
||||
let tLabel = UILabel()
|
||||
tLabel.font = .systemFont(ofSize: 16)
|
||||
tLabel.textColor = UIColor.tui_color(withHex: "333333")
|
||||
return tLabel
|
||||
}()
|
||||
|
||||
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
|
||||
super.init(style: style, reuseIdentifier: reuseIdentifier)
|
||||
self.initUI()
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
func initUI() {
|
||||
self.contentView.addSubview(titlelabel)
|
||||
titlelabel.snp.makeConstraints {
|
||||
$0.left.equalToSuperview().offset(5)
|
||||
$0.top.equalToSuperview().offset(5)
|
||||
$0.right.equalToSuperview().offset(-20)
|
||||
}
|
||||
}
|
||||
|
||||
func updateUI(model: RoomFileBroswerModel) {
|
||||
self.titlelabel.text = model.title
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
//
|
||||
// RoomFileBroswerModel.swift
|
||||
// DemoApp
|
||||
//
|
||||
// Created by CY zhao on 2023/7/4.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
class RoomFileBroswerModel: NSObject {
|
||||
var title: String
|
||||
var path: String
|
||||
|
||||
init(title: String = "", path: String) {
|
||||
self.title = title
|
||||
self.path = path
|
||||
super.init()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
//
|
||||
// RoomFileBrowserViewController.swift
|
||||
// DemoApp
|
||||
//
|
||||
// Created by CY zhao on 2023/7/4.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import UIKit
|
||||
|
||||
@objcMembers public class RoomFileBrowserViewController: UITableViewController {
|
||||
var modelArray: [RoomFileBroswerModel] = []
|
||||
var documentController: UIDocumentInteractionController? = nil
|
||||
var bathPath: String
|
||||
|
||||
public init(bathPath: String) {
|
||||
self.bathPath = bathPath
|
||||
super.init(nibName: nil, bundle: nil)
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
public override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
self.initUI()
|
||||
self.loadData()
|
||||
}
|
||||
|
||||
func initUI() {
|
||||
self.tableView.rowHeight = RoomFileBroswerCellHeight
|
||||
self.tableView.register(RoomFileBroswerCell.self, forCellReuseIdentifier: "RoomFileBroswerCell")
|
||||
|
||||
self.navigationItem.title = self.bathPath
|
||||
self.navigationController?.setNavigationBarHidden(false, animated: false)
|
||||
|
||||
let backBtnItem = UIBarButtonItem(title: " ", style: .plain, target: nil, action: nil)
|
||||
self.navigationItem.backBarButtonItem = backBtnItem
|
||||
}
|
||||
|
||||
func loadData() {
|
||||
guard let fileList = try? FileManager.default.contentsOfDirectory(atPath: self.bathPath) else {
|
||||
return
|
||||
}
|
||||
let sortedList = fileList.sorted { file1, file2 in
|
||||
return file1.localizedStandardCompare(file2) == .orderedAscending
|
||||
}
|
||||
for fileName in sortedList {
|
||||
let path = URL(fileURLWithPath: self.bathPath).appendingPathComponent(fileName).path
|
||||
let model = RoomFileBroswerModel(title: fileName, path: path )
|
||||
self.modelArray.append(model)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Table view data source
|
||||
public override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
||||
return self.modelArray.count
|
||||
}
|
||||
|
||||
public override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
||||
let model = self.modelArray[indexPath.row]
|
||||
let cell = tableView.dequeueReusableCell(withIdentifier: "RoomFileBroswerCell") as! RoomFileBroswerCell
|
||||
cell.updateUI(model: model)
|
||||
return cell
|
||||
}
|
||||
|
||||
public override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
||||
let model = self.modelArray[indexPath.row]
|
||||
|
||||
var isDirectory: ObjCBool = false
|
||||
FileManager.default.fileExists(atPath: model.path, isDirectory: &isDirectory)
|
||||
if isDirectory.boolValue {
|
||||
let vc = RoomFileBrowserViewController(bathPath: self.bathPath)
|
||||
vc.bathPath = model.path
|
||||
self.navigationController?.pushViewController(vc, animated: true)
|
||||
} else {
|
||||
self.handleFile(model: model)
|
||||
}
|
||||
}
|
||||
|
||||
func handleFile(model: RoomFileBroswerModel) {
|
||||
self.documentController = UIDocumentInteractionController(url: URL(fileURLWithPath: model.path))
|
||||
self.documentController?.presentOpenInMenu(from: CGRectZero, in: self.view, animated: true)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user