TestsTested | ✗ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Jan 2018 |
SwiftSwift Version | 4.0 |
SPMSupports SPM | ✗ |
LPAlbum is a simple photo album
LPAlbum is a album including the function of multiple images, photo browsing, camera taking pictures. It is very easy to use
public extension LPAlbum {
public struct Config {
/// 最大选择数量
public var maxSelectCount: Int = 6
/// 每列照片数量
public var columnCount: Int = 4
/// 照片间距
public var photoPadding: CGFloat = 2.0
/// 是否有相机
public var hasCamera: Bool = true
}
public struct Style {
/// `NavigationBar`标题颜色
public static var barTitleColor: UIColor = UIColor.white
/// `NavigationBar`背景颜色
public static var barTintColor: UIColor = UIColor.darkGray
/// `NavigationBar`item文本颜色
public static var tintColor: UIColor = UIColor.white
/// 状态栏样式
public static var statusBarStyle: UIStatusBarStyle = .lightContent
/// 下拉箭头图片
public static var arrowImage: UIImage = Bundle.imageFromBundle("meun_down")!
/// 正常的选择框图片
public static var normalBox: UIImage = Bundle.imageFromBundle("circle_normal")!
/// 选中的选择框图片
public static var selectedBox: UIImage = Bundle.imageFromBundle("circle_selected")!
}
}
public enum AlbumError: Error {
case noAlbumPermission
case noCameraPermission
case moreThanLargestChoiceCount
case savePhotoError
public var localizedDescription: String {
switch self {
case .noAlbumPermission: return String.local("没有相册访问权限")
case .noCameraPermission: return String.local("没有摄像头访问权限")
case .moreThanLargestChoiceCount: return String.local("达到了图片选择最大数量")
case .savePhotoError: return String.local("保存图片失败")
}
}
}
// you can setup style yourself
LPAlbum.Style.barTintColor = .gray
LPAlbum.Style.tintColor = .white
// show
LPAlbum.show(at: self) {
$0.columnCount = 4
$0.hasCamera = true
$0.maxSelectCount = 9 - self.photos.count
}.targeSize({ (size) -> CGSize in
return CGSize(width: 240, height: 240)
}).error {(vc, error) in
vc.show(message: error.localizedDescription)
}.complete { [weak self](images) in
self?.photos.append(contentsOf: images)
self?.collectionView.reloadData()
_ = images.map{ print($0.size) }
}