From b8ba7a10ef668725939bea30ced61d419d5d4a2b Mon Sep 17 00:00:00 2001 From: gaoyu Date: Thu, 14 Sep 2017 01:27:55 +0800 Subject: [PATCH] add UI Style and make AlbumManager public --- LPAlbum/Controllers/LPAlbum.swift | 2 +- LPAlbum/Controllers/LPNavigationController.swift | 6 +++--- LPAlbum/Others/AlbumManager.swift | 6 +++--- LPAlbum/Others/Config.swift | 7 +++++-- LPAlbum/Others/Models.swift | 4 ++-- LPAlbum/Views/AlbumCollectionCell.swift | 4 ++-- LPAlbum/Views/TitleView.swift | 4 ++-- 7 files changed, 18 insertions(+), 15 deletions(-) diff --git a/LPAlbum/Controllers/LPAlbum.swift b/LPAlbum/Controllers/LPAlbum.swift index e51d75f..07ce64a 100644 --- a/LPAlbum/Controllers/LPAlbum.swift +++ b/LPAlbum/Controllers/LPAlbum.swift @@ -4,7 +4,7 @@ // // Created by 郜宇 on 2017/9/8. // Copyright © 2017年 Loopeer. All rights reserved. -// +// TODO: 1. add CompleteSelectAssetsBlock import UIKit import Photos diff --git a/LPAlbum/Controllers/LPNavigationController.swift b/LPAlbum/Controllers/LPNavigationController.swift index 87b3c27..abe6535 100644 --- a/LPAlbum/Controllers/LPNavigationController.swift +++ b/LPAlbum/Controllers/LPNavigationController.swift @@ -11,7 +11,7 @@ import UIKit class LPNavigationController: UINavigationController { override var preferredStatusBarStyle: UIStatusBarStyle { - return LPAlbum.Config.statusBarStyle + return LPAlbum.Style.statusBarStyle } override func viewDidLoad() { @@ -22,8 +22,8 @@ class LPNavigationController: UINavigationController { override init(rootViewController: UIViewController) { super.init(rootViewController: rootViewController) - self.navigationBar.barTintColor = LPAlbum.Config.barTintColor - self.navigationBar.tintColor = LPAlbum.Config.tintColor + self.navigationBar.barTintColor = LPAlbum.Style.barTintColor + self.navigationBar.tintColor = LPAlbum.Style.tintColor } override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) { diff --git a/LPAlbum/Others/AlbumManager.swift b/LPAlbum/Others/AlbumManager.swift index 5dcfbbf..83c53d4 100644 --- a/LPAlbum/Others/AlbumManager.swift +++ b/LPAlbum/Others/AlbumManager.swift @@ -9,11 +9,11 @@ import Foundation import Photos -class AlbumManager { +public class AlbumManager { static let imageManager = PHCachingImageManager() - class func getAlbums() -> [AlbumModel] { + public class func getAlbums() -> [AlbumModel] { //获取智能相册 let smartAlbums = PHAssetCollection.fetchAssetCollections(with: .smartAlbum, subtype: .albumRegular, options: nil) //获取用户创建的相册 @@ -25,7 +25,7 @@ class AlbumManager { } // 根据Asset获取photo - class func getPhoto(asset: PHAsset, targetSize: CGSize, option: PHImageRequestOptions? = nil, resultHandler: @escaping ((UIImage?, [AnyHashable: Any]?) -> Void)) { + public class func getPhoto(asset: PHAsset, targetSize: CGSize, option: PHImageRequestOptions? = nil, resultHandler: @escaping ((UIImage?, [AnyHashable: Any]?) -> Void)) { let defalutOption = PHImageRequestOptions() defalutOption.resizeMode = .fast diff --git a/LPAlbum/Others/Config.swift b/LPAlbum/Others/Config.swift index 5ddd025..dda4a7b 100644 --- a/LPAlbum/Others/Config.swift +++ b/LPAlbum/Others/Config.swift @@ -10,22 +10,25 @@ import Foundation 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 var isSingleSelect: Bool = false + } + + public struct Style { public static var barTitleColor: UIColor = UIColor.white public static var barTintColor: UIColor = UIColor.darkGray 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")! } + } diff --git a/LPAlbum/Others/Models.swift b/LPAlbum/Others/Models.swift index 9cb1be8..40e021f 100644 --- a/LPAlbum/Others/Models.swift +++ b/LPAlbum/Others/Models.swift @@ -9,12 +9,12 @@ import Foundation import Photos -struct AssetModel { +public struct AssetModel { var asset: PHAsset var isSelect: Bool } -struct AlbumModel { +public struct AlbumModel { var name: String var cover: PHAsset var count: Int diff --git a/LPAlbum/Views/AlbumCollectionCell.swift b/LPAlbum/Views/AlbumCollectionCell.swift index 543c7c0..5ec5719 100644 --- a/LPAlbum/Views/AlbumCollectionCell.swift +++ b/LPAlbum/Views/AlbumCollectionCell.swift @@ -37,8 +37,8 @@ class AlbumCollectionCell: UICollectionViewCell { let iconWH = 20.adapt iconButton.frame = CGRect(x: frame.width - padding - iconWH, y: padding, width: iconWH, height: iconWH) - iconButton.setBackgroundImage(LPAlbum.Config.normalBox , for: .normal) - iconButton.setBackgroundImage(LPAlbum.Config.selectedBox, for: .selected) + iconButton.setBackgroundImage(LPAlbum.Style.normalBox , for: .normal) + iconButton.setBackgroundImage(LPAlbum.Style.selectedBox, for: .selected) iconButton.lp_hitEdgeInsets = UIEdgeInsets(top: -5, left: -5, bottom: -5, right: -5) addSubview(photoView) diff --git a/LPAlbum/Views/TitleView.swift b/LPAlbum/Views/TitleView.swift index 70c8341..2a5e6eb 100644 --- a/LPAlbum/Views/TitleView.swift +++ b/LPAlbum/Views/TitleView.swift @@ -29,8 +29,8 @@ class TitleView: UIButton { override init(frame: CGRect) { super.init(frame: frame) - setImage(LPAlbum.Config.arrowImage, for: .normal) - setTitleColor(LPAlbum.Config.barTitleColor, for: .normal) + setImage(LPAlbum.Style.arrowImage, for: .normal) + setTitleColor(LPAlbum.Style.barTitleColor, for: .normal) titleLabel?.font = UIFont.systemFont(ofSize: 17) bounds = CGRect(origin: .zero, size: CGSize(width: 200, height: 40)) addTarget(self, action: #selector(click), for: .touchUpInside)