From d797e759fe00d4265c39f02d43261ef57ba003d3 Mon Sep 17 00:00:00 2001 From: Ramon Gilabert Date: Thu, 19 Nov 2015 09:18:07 +0100 Subject: [PATCH 1/2] Adds static everywhere --- Source/Configuration.swift | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/Source/Configuration.swift b/Source/Configuration.swift index 92843e18..f779d989 100644 --- a/Source/Configuration.swift +++ b/Source/Configuration.swift @@ -8,28 +8,28 @@ public struct Configuration { // MARK: Colors - public var backgroundColor = UIColor(red:0.15, green:0.19, blue:0.24, alpha:1) - public var mainColor = UIColor(red:0.09, green:0.11, blue:0.13, alpha:1) - public var noImagesColor = UIColor(red:0.86, green:0.86, blue:0.86, alpha:1) - public var noCameraColor = UIColor(red:0.86, green:0.86, blue:0.86, alpha:1) - public var settingsColor = UIColor.whiteColor() + public static var backgroundColor = UIColor(red:0.15, green:0.19, blue:0.24, alpha:1) + public static var mainColor = UIColor(red:0.09, green:0.11, blue:0.13, alpha:1) + public static var noImagesColor = UIColor(red:0.86, green:0.86, blue:0.86, alpha:1) + public static var noCameraColor = UIColor(red:0.86, green:0.86, blue:0.86, alpha:1) + public static var settingsColor = UIColor.whiteColor() // MARK: Fonts - public var numberLabelFont = UIFont(name: "HelveticaNeue-Bold", size: 19)! - public var doneButton = UIFont(name: "HelveticaNeue-Medium", size: 19)! - public var flashButton = UIFont(name: "HelveticaNeue-Medium", size: 12)! - public var noImagesFont = UIFont(name: "HelveticaNeue-Medium", size: 18)! - public var noCameraFont = UIFont(name: "HelveticaNeue-Medium", size: 18)! - public var settingsFont = UIFont(name: "HelveticaNeue-Medium", size: 18)! + public static var numberLabelFont = UIFont(name: "HelveticaNeue-Bold", size: 19)! + public static var doneButton = UIFont(name: "HelveticaNeue-Medium", size: 19)! + public static var flashButton = UIFont(name: "HelveticaNeue-Medium", size: 12)! + public static var noImagesFont = UIFont(name: "HelveticaNeue-Medium", size: 18)! + public static var noCameraFont = UIFont(name: "HelveticaNeue-Medium", size: 18)! + public static var settingsFont = UIFont(name: "HelveticaNeue-Medium", size: 18)! // MARK: Titles - public var cancelButtonTitle = "Cancel" - public var doneButtonTitle = "Done" - public var noImagesTitle = "No images available" - public var noCameraTitle = "Camera is not available" - public var settingsTitle = "Settings" + public static var cancelButtonTitle = "Cancel" + public static var doneButtonTitle = "Done" + public static var noImagesTitle = "No images available" + public static var noCameraTitle = "Camera is not available" + public static var settingsTitle = "Settings" // MARK: Dimensions From 3c4d3421852166466288a40df818f5f771cf7dc2 Mon Sep 17 00:00:00 2001 From: Ramon Gilabert Date: Thu, 19 Nov 2015 09:22:59 +0100 Subject: [PATCH 2/2] Adds some configuration --- Source/BottomView/BottomContainerView.swift | 12 +++++------- Source/BottomView/ButtonPicker.swift | 4 +--- Source/CameraView/CameraView.swift | 18 ++++++++---------- Source/Configuration.swift | 6 +----- Source/ImageGallery/ImageGalleryView.swift | 14 ++++++-------- Source/ImagePickerController.swift | 6 ++---- Source/TopView/TopView.swift | 4 +--- 7 files changed, 24 insertions(+), 40 deletions(-) diff --git a/Source/BottomView/BottomContainerView.swift b/Source/BottomView/BottomContainerView.swift index 834d153e..ec601f48 100644 --- a/Source/BottomView/BottomContainerView.swift +++ b/Source/BottomView/BottomContainerView.swift @@ -30,8 +30,8 @@ public class BottomContainerView: UIView { public lazy var doneButton: UIButton = { [unowned self] in let button = UIButton() - button.setTitle(self.pickerConfiguration.cancelButtonTitle, forState: .Normal) - button.titleLabel?.font = self.pickerConfiguration.doneButton + button.setTitle(Configuration.cancelButtonTitle, forState: .Normal) + button.titleLabel?.font = Configuration.doneButton button.addTarget(self, action: "doneButtonDidPress:", forControlEvents: .TouchUpInside) return button @@ -44,7 +44,7 @@ public class BottomContainerView: UIView { lazy var topSeparator: UIView = { [unowned self] in let view = UIView() - view.backgroundColor = self.pickerConfiguration.backgroundColor + view.backgroundColor = Configuration.backgroundColor return view }() @@ -56,8 +56,6 @@ public class BottomContainerView: UIView { return gesture }() - lazy var pickerConfiguration: Configuration = Configuration.sharedInstance - weak var delegate: BottomContainerViewDelegate? var pastCount = 0 @@ -71,7 +69,7 @@ public class BottomContainerView: UIView { $0.translatesAutoresizingMaskIntoConstraints = false } - backgroundColor = pickerConfiguration.backgroundColor + backgroundColor = Configuration.backgroundColor stackView.addGestureRecognizer(tapGestureRecognizer) setupConstraints() @@ -84,7 +82,7 @@ public class BottomContainerView: UIView { // MARK: - Action methods func doneButtonDidPress(button: UIButton) { - if button.currentTitle == pickerConfiguration.cancelButtonTitle { + if button.currentTitle == Configuration.cancelButtonTitle { delegate?.cancelButtonDidPress() } else { delegate?.doneButtonDidPress() diff --git a/Source/BottomView/ButtonPicker.swift b/Source/BottomView/ButtonPicker.swift index 6ab433dc..53e7f6a6 100644 --- a/Source/BottomView/ButtonPicker.swift +++ b/Source/BottomView/ButtonPicker.swift @@ -16,13 +16,11 @@ class ButtonPicker: UIButton { lazy var numberLabel: UILabel = { [unowned self] in let label = UILabel() label.translatesAutoresizingMaskIntoConstraints = false - label.font = self.pickerConfiguration.numberLabelFont + label.font = Configuration.numberLabelFont return label }() - lazy var pickerConfiguration: Configuration = Configuration.sharedInstance - weak var delegate: ButtonPickerDelegate? // MARK: - Initializers diff --git a/Source/CameraView/CameraView.swift b/Source/CameraView/CameraView.swift index ae42c734..912b0a02 100644 --- a/Source/CameraView/CameraView.swift +++ b/Source/CameraView/CameraView.swift @@ -10,8 +10,6 @@ protocol CameraViewDelegate: class { class CameraView: UIViewController { - lazy var pickerConfiguration: Configuration = Configuration.sharedInstance - lazy var blurView: UIVisualEffectView = { [unowned self] in let effect = UIBlurEffect(style: .Dark) let blurView = UIVisualEffectView(effect: effect) @@ -49,9 +47,9 @@ class CameraView: UIViewController { lazy var noCameraLabel: UILabel = { [unowned self] in let label = UILabel() - label.font = self.pickerConfiguration.noCameraFont - label.textColor = self.pickerConfiguration.noCameraColor - label.text = self.pickerConfiguration.noCameraTitle + label.font = Configuration.noCameraFont + label.textColor = Configuration.noCameraColor + label.text = Configuration.noCameraTitle label.sizeToFit() return label @@ -59,10 +57,10 @@ class CameraView: UIViewController { lazy var noCameraButton: UIButton = { [unowned self] in let button = UIButton(type: .System) - let title = NSAttributedString(string: self.pickerConfiguration.settingsTitle, + let title = NSAttributedString(string: Configuration.settingsTitle, attributes: [ - NSFontAttributeName : self.pickerConfiguration.settingsFont, - NSForegroundColorAttributeName : self.pickerConfiguration.settingsColor, + NSFontAttributeName : Configuration.settingsFont, + NSForegroundColorAttributeName : Configuration.settingsColor, ]) button.setAttributedTitle(title, forState: .Normal) @@ -93,8 +91,8 @@ class CameraView: UIViewController { initializeCamera() - view.backgroundColor = self.pickerConfiguration.mainColor - previewLayer?.backgroundColor = self.pickerConfiguration.mainColor.CGColor + view.backgroundColor = Configuration.mainColor + previewLayer?.backgroundColor = Configuration.mainColor.CGColor } // MARK: - Layout diff --git a/Source/Configuration.swift b/Source/Configuration.swift index f779d989..cbe911ba 100644 --- a/Source/Configuration.swift +++ b/Source/Configuration.swift @@ -2,10 +2,6 @@ import UIKit public struct Configuration { - static let sharedInstance = Configuration() - - public init() { } - // MARK: Colors public static var backgroundColor = UIColor(red:0.15, green:0.19, blue:0.24, alpha:1) @@ -33,5 +29,5 @@ public struct Configuration { // MARK: Dimensions - public var cellSpacing: CGFloat = 2 + public static var cellSpacing: CGFloat = 2 } diff --git a/Source/ImageGallery/ImageGalleryView.swift b/Source/ImageGallery/ImageGalleryView.swift index b21a182a..f929e289 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.pickerConfiguration.mainColor + collectionView.backgroundColor = Configuration.mainColor collectionView.showsHorizontalScrollIndicator = false return collectionView @@ -34,7 +34,7 @@ public class ImageGalleryView: UIView { lazy var collectionViewLayout: UICollectionViewLayout = { [unowned self] in let layout = UICollectionViewFlowLayout() layout.scrollDirection = .Horizontal - layout.minimumInteritemSpacing = self.pickerConfiguration.cellSpacing + layout.minimumInteritemSpacing = Configuration.cellSpacing layout.minimumLineSpacing = 2 layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0) @@ -70,13 +70,11 @@ public class ImageGalleryView: UIView { lazy var assets = [PHAsset]() - lazy var pickerConfiguration: Configuration = Configuration.sharedInstance - public lazy var noImagesLabel: UILabel = { [unowned self] in let label = UILabel() - label.font = self.pickerConfiguration.noImagesFont - label.textColor = self.pickerConfiguration.noImagesColor - label.text = self.pickerConfiguration.noImagesTitle + label.font = Configuration.noImagesFont + label.textColor = Configuration.noImagesColor + label.text = Configuration.noImagesTitle label.alpha = 0 label.sizeToFit() self.addSubview(label) @@ -96,7 +94,7 @@ public class ImageGalleryView: UIView { override init(frame: CGRect) { super.init(frame: frame) - backgroundColor = pickerConfiguration.mainColor + backgroundColor = Configuration.mainColor collectionView.registerClass(ImageGalleryViewCell.self, forCellWithReuseIdentifier: CollectionView.reusableIdentifier) diff --git a/Source/ImagePickerController.swift b/Source/ImagePickerController.swift index 85e27c5d..b4d9366f 100644 --- a/Source/ImagePickerController.swift +++ b/Source/ImagePickerController.swift @@ -58,8 +58,6 @@ public class ImagePickerController: UIViewController { return gesture }() - public lazy var pickerConfiguration: Configuration = Configuration.sharedInstance - public weak var delegate: ImagePickerDelegate? public var stack = ImageStack() let totalHeight = UIScreen.mainScreen().bounds.size.height @@ -87,7 +85,7 @@ public class ImagePickerController: UIViewController { } view.backgroundColor = .whiteColor() - view.backgroundColor = pickerConfiguration.mainColor + view.backgroundColor = Configuration.mainColor cameraController.view.addGestureRecognizer(panGestureRecognizer) subscribe() @@ -142,7 +140,7 @@ public class ImagePickerController: UIViewController { guard let sender = notification.object as? ImageStack else { return } let title = !sender.assets.isEmpty ? - pickerConfiguration.doneButtonTitle : pickerConfiguration.cancelButtonTitle + Configuration.doneButtonTitle : Configuration.cancelButtonTitle bottomContainer.doneButton.setTitle(title, forState: .Normal) } diff --git a/Source/TopView/TopView.swift b/Source/TopView/TopView.swift index 0cdabff2..e44742b1 100644 --- a/Source/TopView/TopView.swift +++ b/Source/TopView/TopView.swift @@ -24,7 +24,7 @@ class TopView: UIView { button.titleEdgeInsets = UIEdgeInsetsMake(0, 4, 0, 0) button.setTitleColor(.whiteColor(), forState: .Normal) button.setTitleColor(.whiteColor(), forState: .Highlighted) - button.titleLabel?.font = self.pickerConfiguration.flashButton + button.titleLabel?.font = Configuration.flashButton button.addTarget(self, action: "flashButtonDidPress:", forControlEvents: .TouchUpInside) button.contentHorizontalAlignment = .Left @@ -40,8 +40,6 @@ class TopView: UIView { return button }() - lazy var pickerConfiguration: Configuration = Configuration.sharedInstance - weak var delegate: TopViewDelegate? // MARK: - Initializers