Commit c65bd2ec by Sarkizz

相册添加自定义设置

parent 4626d40f
......@@ -9,15 +9,30 @@
import UIKit
import SnapKit
private let checkboxSize = CGSize(width: 30, height: 30)
private let checkboxEmptyImage = MRCheckBoxImage.image(with: MRCheckBoxOptions.defaultEmpty(checkboxSize))
private let checkboxCheckImage = MRCheckBoxImage.image(with: MRCheckBoxOptions.defaultCheck(checkboxSize))
public final class MRAlbumCell: UICollectionViewCell {
static let defaultCheckboxSize = CGSize(width: 30, height: 30)
public let imageView = UIImageView()
public let selectedMask = UIView()
public let checkbox = UIButton()
public var checkboxSize = MRAlbumCell.defaultCheckboxSize {
didSet {
resetCheckboxOptions()
}
}
public var deselectedCheckboxOptions: MRCheckBoxOptions? {
didSet {
resetCheckboxInterface()
}
}
public var selectedCheckboxOptions: MRCheckBoxOptions = .defaultCheck(MRAlbumCell.defaultCheckboxSize) {
didSet {
resetCheckboxInterface()
}
}
public var check: ((_ cell: MRAlbumCell) -> Void)?
public override init(frame: CGRect) {
......@@ -53,8 +68,7 @@ extension MRAlbumCell {
selectedMask.isUserInteractionEnabled = false
selectedMask.isHidden = true
checkbox.setImage(nil, for: .normal)
checkbox.setImage(checkboxCheckImage, for: .selected)
resetCheckboxInterface()
checkbox.addTarget(self, action: #selector(checkButtonPressed(_:)), for: .touchUpInside)
contentView.addSubview(imageView)
......@@ -62,6 +76,22 @@ extension MRAlbumCell {
contentView.addSubview(checkbox)
}
private func resetCheckboxInterface() {
if let options = deselectedCheckboxOptions {
checkbox.setImage(MRCheckBoxImage.image(with: options), for: .normal)
}
checkbox.setImage(MRCheckBoxImage.image(with: selectedCheckboxOptions), for: .selected)
}
private func resetCheckboxOptions() {
deselectedCheckboxOptions?.size = checkboxSize
selectedCheckboxOptions.size = checkboxSize
checkbox.snp.updateConstraints { (make) in
make.size.equalTo(checkboxSize)
}
}
private func layoutViews() {
imageView.snp.makeConstraints { (make) in
make.edges.equalToSuperview()
......
......@@ -18,24 +18,28 @@ public struct MRCheckBoxOptions {
var curveLineColor: UIColor
var backgroundColor: UIColor
static func defaultEmpty(_ size: CGSize) -> MRCheckBoxOptions {
return .init(size: size,
type: .empty,
checkLineWidth: 3,
curveLineWidth: 2,
checkLineColor: .white,
curveLineColor: .white,
backgroundColor: .clear)
public static func defaultEmpty(_ size: CGSize) -> MRCheckBoxOptions {
return custom(size: size, type: .empty, backgroundColor: .clear)
}
public static func defaultCheck(_ size: CGSize) -> MRCheckBoxOptions {
return custom(size: size)
}
static func defaultCheck(_ size: CGSize) -> MRCheckBoxOptions {
public static func custom(size: CGSize,
type: MRCheckBoxType = .check,
checkLineWidth: CGFloat = 3,
curveLineWidth: CGFloat = 2,
checkLineColor: UIColor = .white,
curveLineColor: UIColor = .white,
backgroundColor: UIColor = .green) -> MRCheckBoxOptions {
return .init(size: size,
type: .check,
checkLineWidth: 3,
curveLineWidth: 2,
checkLineColor: .white,
curveLineColor: .white,
backgroundColor: .green)
type: type,
checkLineWidth: checkLineWidth,
curveLineWidth: curveLineWidth,
checkLineColor: checkLineColor,
curveLineColor: curveLineColor,
backgroundColor: backgroundColor)
}
}
......
......@@ -17,6 +17,7 @@ public enum MRAlbumListStatus {
case finish
}
public typealias MRAlbumCustomCellSetting = (_ cell: MRAlbumCell) -> Void
public typealias MRAlbumDidSelect = (_ vc: MRAlbumListViewController, _ assests: [PHAsset]) -> Void
open class MRAlbumListViewController: UIViewController {
......@@ -45,6 +46,8 @@ open class MRAlbumListViewController: UIViewController {
statusDidChange()
}
}
public var customCellSetting: MRAlbumCustomCellSetting?
public var assests: PHFetchResult<PHAsset>?
public var selectedAssests = [PHAsset]()
......@@ -94,6 +97,7 @@ open class MRAlbumListViewController: UIViewController {
open func cellSetting(_ cell: UICollectionViewCell, at indexPath: IndexPath) {
if let cell = cell as? MRAlbumCell, let assest = assests?[indexPath.row] {
customCellSetting?(cell)
requestImage(with: assest, size: thumbImageSize * UIScreen.main.scale) { image, info in
cell.setImage(image)
}
......
......@@ -18,6 +18,7 @@ public enum SAPhotoPickerType {
}
public typealias SAPhotoPickerComplateBlock = (_ images: [UIImage]?, _ imageURLs: [URL]?, _ error: Error?) -> Void
public typealias SAPhotoPickerMutableSelectionAlbumSetting = (_ picker: SAPhotoPicker, _ vc: SAMutableSelectionAlbum) -> Void
extension SAPhotoPicker {
//config keys
......@@ -40,7 +41,7 @@ extension SAPhotoPicker.ConfigKey {
public class SAPhotoPicker: NSObject {
public static let shared = SAPhotoPicker()
var config: [SAPhotoPicker.ConfigKey: Any] = [
public var config: [SAPhotoPicker.ConfigKey: Any] = [
.cameraTitle: "拍照",
.libraryTitle: "相册",
.albumTitle: "相册",
......@@ -48,6 +49,8 @@ public class SAPhotoPicker: NSObject {
.editable: false
]
public var mutableSelectionAlbumSetting: SAPhotoPickerMutableSelectionAlbumSetting?
private var imageMaxSize: CGSize?
private var complateBlock: SAPhotoPickerComplateBlock?
......@@ -112,7 +115,9 @@ extension SAPhotoPicker {
self.complateBlock?(nil, nil, nil)
vc.dismiss(animated: true)
}
UIApplication.shared.keyWindow?.rootViewController?.present(vc, animated: true, completion: nil)
mutableSelectionAlbumSetting?(self, vc)
let nav = UINavigationController(rootViewController: vc)
UIApplication.shared.keyWindow?.rootViewController?.present(nav, animated: true, completion: nil)
}
private func navTitle(with sourceType: UIImagePickerController.SourceType) -> String? {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment