Commit 365cba14 by Daniel Dahan

development: added convenience to CollectionView

parent ca7be84e
...@@ -99,14 +99,21 @@ open class CollectionView: UICollectionView { ...@@ -99,14 +99,21 @@ open class CollectionView: UICollectionView {
super.init(frame: frame, collectionViewLayout: layout) super.init(frame: frame, collectionViewLayout: layout)
prepare() prepare()
} }
/**
An initializer that initializes the object.
- Parameter collectionViewLayout: A UICollectionViewLayout reference.
*/
public convenience init(collectionViewLayout layout: UICollectionViewLayout) {
self.init(frame: .zero, collectionViewLayout: layout)
}
/** /**
An initializer that initializes the object. An initializer that initializes the object.
- Parameter frame: A CGRect defining the view's frame. - Parameter frame: A CGRect defining the view's frame.
*/ */
public init(frame: CGRect) { public convenience init(frame: CGRect) {
super.init(frame: frame, collectionViewLayout: CollectionViewLayout()) self.init(frame: frame, collectionViewLayout: CollectionViewLayout())
prepare()
} }
/// A convenience initializer that initializes the object. /// A convenience initializer that initializes the object.
......
...@@ -71,7 +71,7 @@ open class CollectionViewController: UIViewController { ...@@ -71,7 +71,7 @@ open class CollectionViewController: UIViewController {
open override func viewWillLayoutSubviews() { open override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews() super.viewWillLayoutSubviews()
collectionView.frame = view.bounds layoutSubviews()
} }
/** /**
...@@ -87,6 +87,11 @@ open class CollectionViewController: UIViewController { ...@@ -87,6 +87,11 @@ open class CollectionViewController: UIViewController {
view.contentScaleFactor = Screen.scale view.contentScaleFactor = Screen.scale
prepareCollectionView() prepareCollectionView()
} }
/// Calls the layout functions for the view heirarchy.
open func layoutSubviews() {
layoutCollectionView()
}
} }
extension CollectionViewController { extension CollectionViewController {
...@@ -95,6 +100,14 @@ extension CollectionViewController { ...@@ -95,6 +100,14 @@ extension CollectionViewController {
collectionView.delegate = self collectionView.delegate = self
collectionView.dataSource = self collectionView.dataSource = self
view.addSubview(collectionView) view.addSubview(collectionView)
layoutCollectionView()
}
}
extension CollectionViewController {
/// Sets the frame for the collectionView.
fileprivate func layoutCollectionView() {
collectionView.frame = view.bounds
} }
} }
......
...@@ -108,8 +108,7 @@ open class NavigationController: UINavigationController { ...@@ -108,8 +108,7 @@ open class NavigationController: UINavigationController {
open override func viewWillLayoutSubviews() { open override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews() super.viewWillLayoutSubviews()
navigationBar.setNeedsLayout() layoutSubviews()
navigationBar.layoutIfNeeded()
} }
/** /**
...@@ -133,6 +132,12 @@ open class NavigationController: UINavigationController { ...@@ -133,6 +132,12 @@ open class NavigationController: UINavigationController {
v.delegate = self v.delegate = self
} }
} }
/// Calls the layout functions for the view heirarchy.
open func layoutSubviews() {
navigationBar.setNeedsLayout()
navigationBar.layoutIfNeeded()
}
} }
extension NavigationController: UINavigationBarDelegate { extension NavigationController: UINavigationBarDelegate {
......
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 to comment