diff --git a/Source/BottomView/BottomContainerView.swift b/Source/BottomView/BottomContainerView.swift index 411cf3b8..906f12d5 100644 --- a/Source/BottomView/BottomContainerView.swift +++ b/Source/BottomView/BottomContainerView.swift @@ -30,8 +30,8 @@ class BottomContainerView: UIView { lazy var doneButton: UIButton = { [unowned self] in let button = UIButton() - button.setTitle(self.configuration.cancelButtonTitle, forState: .Normal) - button.titleLabel?.font = self.configuration.doneButton + button.setTitle(self.pickerConfiguration.cancelButtonTitle, forState: .Normal) + button.titleLabel?.font = self.pickerConfiguration.doneButton button.addTarget(self, action: "doneButtonDidPress:", forControlEvents: .TouchUpInside) return button @@ -42,14 +42,11 @@ class BottomContainerView: UIView { return view }() - lazy var configuration: PickerConfiguration = { - let configuration = PickerConfiguration() - return configuration - }() + lazy var pickerConfiguration: Configuration = Configuration.sharedInstance lazy var topSeparator: UIView = { [unowned self] in let view = UIView() - view.backgroundColor = self.configuration.backgroundColor + view.backgroundColor = self.pickerConfiguration.backgroundColor return view }() @@ -74,7 +71,7 @@ class BottomContainerView: UIView { view.translatesAutoresizingMaskIntoConstraints = false } - backgroundColor = configuration.backgroundColor + backgroundColor = pickerConfiguration.backgroundColor stackView.addGestureRecognizer(tapGestureRecognizer) setupConstraints() @@ -87,7 +84,7 @@ class BottomContainerView: UIView { // MARK: - Action methods func doneButtonDidPress(button: UIButton) { - if button.currentTitle == configuration.cancelButtonTitle { + if button.currentTitle == pickerConfiguration.cancelButtonTitle { delegate?.cancelButtonDidPress() } else { delegate?.doneButtonDidPress() diff --git a/Source/BottomView/ButtonPicker.swift b/Source/BottomView/ButtonPicker.swift index 78b0c809..6ab433dc 100644 --- a/Source/BottomView/ButtonPicker.swift +++ b/Source/BottomView/ButtonPicker.swift @@ -16,15 +16,12 @@ class ButtonPicker: UIButton { lazy var numberLabel: UILabel = { [unowned self] in let label = UILabel() label.translatesAutoresizingMaskIntoConstraints = false - label.font = self.configuration.numberLabelFont + label.font = self.pickerConfiguration.numberLabelFont return label }() - lazy var configuration: PickerConfiguration = { - let configuration = PickerConfiguration() - return configuration - }() + lazy var pickerConfiguration: Configuration = Configuration.sharedInstance weak var delegate: ButtonPickerDelegate? diff --git a/Source/CameraView/CameraView.swift b/Source/CameraView/CameraView.swift index 2bff0b60..37b04007 100644 --- a/Source/CameraView/CameraView.swift +++ b/Source/CameraView/CameraView.swift @@ -10,10 +10,7 @@ protocol CameraViewDelegate: class { class CameraView: UIViewController { - lazy var configuration: PickerConfiguration = { - let configuration = PickerConfiguration() - return configuration - }() + lazy var pickerConfiguration: Configuration = Configuration.sharedInstance lazy var blurView: UIVisualEffectView = { [unowned self] in let effect = UIBlurEffect(style: .Dark) @@ -64,8 +61,8 @@ class CameraView: UIViewController { initializeCamera() - view.backgroundColor = self.configuration.mainColor - previewLayer?.backgroundColor = self.configuration.mainColor.CGColor + view.backgroundColor = self.pickerConfiguration.mainColor + previewLayer?.backgroundColor = self.pickerConfiguration.mainColor.CGColor } // MARK: - Initialize camera diff --git a/Source/PickerConfiguration.swift b/Source/Configuration.swift similarity index 89% rename from Source/PickerConfiguration.swift rename to Source/Configuration.swift index ddb8ac07..f5fbc70c 100644 --- a/Source/PickerConfiguration.swift +++ b/Source/Configuration.swift @@ -1,6 +1,10 @@ import UIKit -public class PickerConfiguration { +public struct Configuration { + + static let sharedInstance = Configuration() + + public init() { } // MARK: Colors diff --git a/Source/ImageGallery/ImageGalleryView.swift b/Source/ImageGallery/ImageGalleryView.swift index 7436f803..7bfe7d1c 100644 --- a/Source/ImageGallery/ImageGalleryView.swift +++ b/Source/ImageGallery/ImageGalleryView.swift @@ -25,7 +25,7 @@ public class ImageGalleryView: UIView { let collectionView = UICollectionView(frame: CGRectMake(0, 0, 0, 0), collectionViewLayout: self.collectionViewLayout) collectionView.translatesAutoresizingMaskIntoConstraints = false - collectionView.backgroundColor = self.configuration.mainColor + collectionView.backgroundColor = self.pickerConfiguration.mainColor collectionView.showsHorizontalScrollIndicator = false collectionView.layer.anchorPoint = CGPointMake(0.5, 0.5) @@ -35,7 +35,7 @@ public class ImageGalleryView: UIView { lazy var collectionViewLayout: UICollectionViewLayout = { [unowned self] in let layout = UICollectionViewFlowLayout() layout.scrollDirection = .Horizontal - layout.minimumInteritemSpacing = self.configuration.cellSpacing + layout.minimumInteritemSpacing = self.pickerConfiguration.cellSpacing layout.minimumLineSpacing = 2 layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0) @@ -71,16 +71,13 @@ public class ImageGalleryView: UIView { lazy var assets = [PHAsset]() - lazy var configuration: PickerConfiguration = { - let configuration = PickerConfiguration() - return configuration - }() + lazy var pickerConfiguration: Configuration = Configuration.sharedInstance lazy var noImagesLabel: UILabel = { [unowned self] in let label = UILabel() - label.font = self.configuration.noImagesFont - label.textColor = self.configuration.noImagesColor - label.text = self.configuration.noImagesTitle + label.font = self.pickerConfiguration.noImagesFont + label.textColor = self.pickerConfiguration.noImagesColor + label.text = self.pickerConfiguration.noImagesTitle label.alpha = 0 label.sizeToFit() self.addSubview(label) diff --git a/Source/ImagePickerController.swift b/Source/ImagePickerController.swift index a1449e4e..a529441a 100644 --- a/Source/ImagePickerController.swift +++ b/Source/ImagePickerController.swift @@ -57,7 +57,7 @@ public class ImagePickerController: UIViewController { return gesture }() - lazy var configuration: PickerConfiguration = PickerConfiguration() + lazy var pickerConfiguration: Configuration = Configuration.sharedInstance public weak var delegate: ImagePickerDelegate? public var stack = ImageStack() @@ -86,7 +86,7 @@ public class ImagePickerController: UIViewController { } view.backgroundColor = .whiteColor() - view.backgroundColor = configuration.mainColor + view.backgroundColor = pickerConfiguration.mainColor cameraController.view.addGestureRecognizer(panGestureRecognizer) subscribe() @@ -141,7 +141,7 @@ public class ImagePickerController: UIViewController { guard let sender = notification.object as? ImageStack else { return } let title = !sender.assets.isEmpty ? - configuration.doneButtonTitle : configuration.cancelButtonTitle + pickerConfiguration.doneButtonTitle : pickerConfiguration.cancelButtonTitle bottomContainer.doneButton.setTitle(title, forState: .Normal) } diff --git a/Source/TopView/TopView.swift b/Source/TopView/TopView.swift index a5c6c8ea..804a2cfb 100644 --- a/Source/TopView/TopView.swift +++ b/Source/TopView/TopView.swift @@ -21,7 +21,7 @@ class TopView: UIView { button.titleEdgeInsets = UIEdgeInsetsMake(0, 4, 0, 0) button.setTitleColor(UIColor(red:0.98, green:0.98, blue:0.45, alpha:1), forState: .Normal) button.setTitleColor(UIColor(red:0.52, green:0.52, blue:0.24, alpha:1), forState: .Highlighted) - button.titleLabel?.font = self.configuration.flashButton + button.titleLabel?.font = self.pickerConfiguration.flashButton button.addTarget(self, action: "flashButtonDidPress:", forControlEvents: .TouchUpInside) button.contentHorizontalAlignment = .Left @@ -37,10 +37,7 @@ class TopView: UIView { return button }() - lazy var configuration: PickerConfiguration = { - let configuration = PickerConfiguration() - return configuration - }() + lazy var pickerConfiguration: Configuration = Configuration.sharedInstance weak var delegate: TopViewDelegate?