Commit b5da540b by Daniel Dahan

working copy of BottomNavigationBar with App example project

parent 5c193224
...@@ -41,7 +41,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { ...@@ -41,7 +41,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
let bottomNavigationController: BottomNavigationController = BottomNavigationController() let bottomNavigationController: BottomNavigationController = BottomNavigationController()
bottomNavigationController.viewControllers = [AppMenuViewController(rootViewController: AppNavigationController(rootViewController: RecipesViewController())), VideoViewController(), PhotoViewController()] bottomNavigationController.viewControllers = [AppMenuViewController(rootViewController: AppNavigationController(rootViewController: RecipesViewController())), VideoViewController(), PhotoViewController()]
bottomNavigationController.selectedIndex = 0 bottomNavigationController.selectedIndex = 0
bottomNavigationController.tabBar.tintColor = MaterialColor.lightBlue.base bottomNavigationController.tabBar.tintColor = MaterialColor.white
bottomNavigationController.tabBar.backgroundColor = MaterialColor.grey.darken4 bottomNavigationController.tabBar.backgroundColor = MaterialColor.grey.darken4
// Override point for customization after application launch. // Override point for customization after application launch.
......
...@@ -154,10 +154,9 @@ class AppMenuViewController: MenuViewController { ...@@ -154,10 +154,9 @@ class AppMenuViewController: MenuViewController {
/// Prepare tabBarItem. /// Prepare tabBarItem.
private func prepareTabBarItem() { private func prepareTabBarItem() {
tabBarItem.title = "Recipes"
tabBarItem.image = MaterialIcon.photoLibrary tabBarItem.image = MaterialIcon.photoLibrary
tabBarItem.setTitleColor(MaterialColor.grey.base, forState: .Normal) tabBarItem.setTitleColor(MaterialColor.grey.base, forState: .Normal)
tabBarItem.setTitleColor(MaterialColor.lightBlue.base, forState: .Selected) tabBarItem.setTitleColor(MaterialColor.white, forState: .Selected)
} }
} }
...@@ -47,11 +47,11 @@ class ItemViewController: UIViewController { ...@@ -47,11 +47,11 @@ class ItemViewController: UIViewController {
/// NavigationBar share button. /// NavigationBar share button.
private var shareButton: FlatButton! private var shareButton: FlatButton!
/// MaterialCollectionView. /// MaterialScrollView.
private var collectionView: MaterialCollectionView! private var scrollView: UIScrollView!
/// Image thumbnail height. /// Image height for the imageCardView.
private var thumbnailHieght: CGFloat = 300 private var imageHeight: CGFloat = 300
override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) { override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil) super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
...@@ -72,12 +72,21 @@ class ItemViewController: UIViewController { ...@@ -72,12 +72,21 @@ class ItemViewController: UIViewController {
prepareTitleLabel() prepareTitleLabel()
prepareShareButton() prepareShareButton()
prepareNavigationBar() prepareNavigationBar()
prepareScrollView()
prepareImageCardView() prepareImageCardView()
} }
/// Handler for shareButton. override func viewWillLayoutSubviews() {
internal func handleShareButton() { super.viewWillLayoutSubviews()
print("Share Button Pressed") scrollView.frame = view.bounds
scrollView.removeConstraints(scrollView.constraints)
MaterialLayout.width(scrollView, child: imageCardView, width: scrollView.bounds.width)
imageCardView.layoutIfNeeded()
scrollView.contentSize = CGSizeMake(view.bounds.width, imageCardView.height)
imageCardView.reloadView()
imageCardView.contentsGravityPreset = .ResizeAspectFill
print(scrollView.frame)
print(scrollView.contentSize)
} }
private func prepareView() { private func prepareView() {
...@@ -108,20 +117,24 @@ class ItemViewController: UIViewController { ...@@ -108,20 +117,24 @@ class ItemViewController: UIViewController {
shareButton.pulseColor = MaterialColor.white shareButton.pulseColor = MaterialColor.white
shareButton.setImage(image, forState: .Normal) shareButton.setImage(image, forState: .Normal)
shareButton.setImage(image, forState: .Highlighted) shareButton.setImage(image, forState: .Highlighted)
shareButton.addTarget(self, action: #selector(handleShareButton), forControlEvents: .TouchUpInside)
} }
/// Prepares view. /// Prepares the navigationItem.
private func prepareNavigationBar() { private func prepareNavigationBar() {
navigationItem.titleLabel = titleLabel navigationItem.titleLabel = titleLabel
navigationItem.detailLabel = detailLabel navigationItem.detailLabel = detailLabel
navigationItem.rightControls = [shareButton] navigationItem.rightControls = [shareButton]
} }
/// Prepares the scrollView.
private func prepareScrollView() {
scrollView = UIScrollView(frame: view.bounds)
view.addSubview(scrollView)
}
/// Prepares the imageCardView. /// Prepares the imageCardView.
private func prepareImageCardView() { private func prepareImageCardView() {
if let data: Dictionary<String, AnyObject> = dataSource.data as? Dictionary<String, AnyObject> { if let data: Dictionary<String, AnyObject> = dataSource.data as? Dictionary<String, AnyObject> {
let height: CGFloat = 300
imageCardView = ImageCardView() imageCardView = ImageCardView()
...@@ -136,7 +149,7 @@ class ItemViewController: UIViewController { ...@@ -136,7 +149,7 @@ class ItemViewController: UIViewController {
imageCardView.titleLabel?.text = data["title"] as? String imageCardView.titleLabel?.text = data["title"] as? String
imageCardView.titleLabel?.textColor = MaterialColor.grey.darken4 imageCardView.titleLabel?.textColor = MaterialColor.grey.darken4
imageCardView.titleLabel?.font = RobotoFont.regularWithSize(20) imageCardView.titleLabel?.font = RobotoFont.regularWithSize(20)
imageCardView.titleLabelInset.top = height imageCardView.titleLabelInset.top = imageHeight
let detailLabel: UILabel = UILabel() let detailLabel: UILabel = UILabel()
detailLabel.text = data["detail"] as? String detailLabel.text = data["detail"] as? String
...@@ -148,14 +161,12 @@ class ItemViewController: UIViewController { ...@@ -148,14 +161,12 @@ class ItemViewController: UIViewController {
imageCardView.detailViewInset.top = 52 imageCardView.detailViewInset.top = 52
if let v: CGFloat = view.bounds.width { if let v: CGFloat = view.bounds.width {
let image: UIImage? = UIImage(named: data["image"] as! String)?.resize(toWidth: v)?.crop(toWidth: v, toHeight: height) let image: UIImage? = UIImage(named: data["image"] as! String)?.resize(toWidth: v)?.crop(toWidth: v, toHeight: imageHeight)
imageCardView.image = image imageCardView.image = image
} }
view.addSubview(imageCardView) scrollView.addSubview(imageCardView)
imageCardView.translatesAutoresizingMaskIntoConstraints = false imageCardView.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.alignFromTop(view, child: imageCardView)
MaterialLayout.alignToParentHorizontally(view, child: imageCardView)
} }
} }
} }
...@@ -57,9 +57,8 @@ class PhotoViewController: UIViewController { ...@@ -57,9 +57,8 @@ class PhotoViewController: UIViewController {
/// Prepare tabBarItem. /// Prepare tabBarItem.
private func prepareTabBarItem() { private func prepareTabBarItem() {
tabBarItem.title = "Photo"
tabBarItem.image = MaterialIcon.photoCamera tabBarItem.image = MaterialIcon.photoCamera
tabBarItem.setTitleColor(MaterialColor.grey.base, forState: .Normal) tabBarItem.setTitleColor(MaterialColor.grey.base, forState: .Normal)
tabBarItem.setTitleColor(MaterialColor.lightBlue.base, forState: .Selected) tabBarItem.setTitleColor(MaterialColor.white, forState: .Selected)
} }
} }
...@@ -158,54 +158,6 @@ class RecipesViewController: UIViewController { ...@@ -158,54 +158,6 @@ class RecipesViewController: UIViewController {
"date": "February 26, 2016", "date": "February 26, 2016",
"image": "VeganPieAbove" "image": "VeganPieAbove"
] ]
),
MaterialDataSourceItem(
data: [
"title": "Crepe Indulgence",
"detail": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
"date": "February 26, 2016",
"image": "AssortmentOfDessert"
]
),
MaterialDataSourceItem(
data: [
"title": "Avocado Chocolate Cake",
"detail": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
"date": "February 26, 2016",
"image": "AssortmentOfFood"
]
),
MaterialDataSourceItem(
data: [
"title": "Avocado Ice-Cream",
"detail": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
"date": "February 26, 2016",
"image": "AvocadoIceCream"
]
),
MaterialDataSourceItem(
data: [
"title": "Raw Vegan Chocolate Cookies",
"detail": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
"date": "February 26, 2016",
"image": "HeartCookies"
]
),
MaterialDataSourceItem(
data: [
"title": "Raw Vegan Nutty Sweets",
"detail": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
"date": "February 26, 2016",
"image": "VeganHempBalls"
]
),
MaterialDataSourceItem(
data: [
"title": "Blueberry Tart",
"detail": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
"date": "February 26, 2016",
"image": "VeganPieAbove"
]
) )
] ]
} }
...@@ -250,7 +202,7 @@ class RecipesViewController: UIViewController { ...@@ -250,7 +202,7 @@ class RecipesViewController: UIViewController {
searchButton.addTarget(self, action: #selector(handleSearchButton), forControlEvents: .TouchUpInside) searchButton.addTarget(self, action: #selector(handleSearchButton), forControlEvents: .TouchUpInside)
} }
/// Prepares the NavigationBar. /// Prepares the navigationItem.
private func prepareNavigationBar() { private func prepareNavigationBar() {
navigationItem.titleLabel = titleLabel navigationItem.titleLabel = titleLabel
navigationItem.leftControls = [menuButton] navigationItem.leftControls = [menuButton]
......
...@@ -57,9 +57,8 @@ class VideoViewController: UIViewController { ...@@ -57,9 +57,8 @@ class VideoViewController: UIViewController {
/// Prepare tabBarItem. /// Prepare tabBarItem.
private func prepareTabBarItem() { private func prepareTabBarItem() {
tabBarItem.title = "Video"
tabBarItem.image = MaterialIcon.videocam tabBarItem.image = MaterialIcon.videocam
tabBarItem.setTitleColor(MaterialColor.grey.base, forState: .Normal) tabBarItem.setTitleColor(MaterialColor.grey.base, forState: .Normal)
tabBarItem.setTitleColor(MaterialColor.lightBlue.base, forState: .Selected) tabBarItem.setTitleColor(MaterialColor.white, forState: .Selected)
} }
} }
...@@ -119,7 +119,7 @@ public class MenuViewController : UIViewController { ...@@ -119,7 +119,7 @@ public class MenuViewController : UIViewController {
self.rootViewController.removeFromParentViewController() self.rootViewController.removeFromParentViewController()
self.rootViewController = toViewController self.rootViewController = toViewController
self.rootViewController.view.clipsToBounds = true self.rootViewController.view.clipsToBounds = true
self.rootViewController.view.autoresizingMask = .FlexibleWidth self.rootViewController.view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
self.view.sendSubviewToBack(self.rootViewController.view) self.view.sendSubviewToBack(self.rootViewController.view)
completion?(result) completion?(result)
}) })
...@@ -169,7 +169,7 @@ public class MenuViewController : UIViewController { ...@@ -169,7 +169,7 @@ public class MenuViewController : UIViewController {
/// A method that prepares the rootViewController. /// A method that prepares the rootViewController.
private func prepareRootViewController() { private func prepareRootViewController() {
rootViewController.view.clipsToBounds = true rootViewController.view.clipsToBounds = true
rootViewController.view.autoresizingMask = .FlexibleWidth rootViewController.view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
prepareViewControllerWithinContainer(rootViewController, container: view) prepareViewControllerWithinContainer(rootViewController, container: view)
} }
......
...@@ -349,7 +349,7 @@ public class SideNavigationController : UIViewController, UIGestureRecognizerDel ...@@ -349,7 +349,7 @@ public class SideNavigationController : UIViewController, UIGestureRecognizerDel
self.rootViewController.removeFromParentViewController() self.rootViewController.removeFromParentViewController()
self.rootViewController = toViewController self.rootViewController = toViewController
self.rootViewController.view.clipsToBounds = true self.rootViewController.view.clipsToBounds = true
self.rootViewController.view.autoresizingMask = .FlexibleWidth self.rootViewController.view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
self.view.sendSubviewToBack(self.rootViewController.view) self.view.sendSubviewToBack(self.rootViewController.view)
completion?(result) completion?(result)
}) })
...@@ -737,7 +737,7 @@ public class SideNavigationController : UIViewController, UIGestureRecognizerDel ...@@ -737,7 +737,7 @@ public class SideNavigationController : UIViewController, UIGestureRecognizerDel
/// A method that prepares the rootViewController. /// A method that prepares the rootViewController.
private func prepareRootViewController() { private func prepareRootViewController() {
rootViewController.view.clipsToBounds = true rootViewController.view.clipsToBounds = true
rootViewController.view.autoresizingMask = .FlexibleWidth rootViewController.view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
prepareViewControllerWithinContainer(rootViewController, container: view) prepareViewControllerWithinContainer(rootViewController, container: view)
} }
...@@ -745,6 +745,7 @@ public class SideNavigationController : UIViewController, UIGestureRecognizerDel ...@@ -745,6 +745,7 @@ public class SideNavigationController : UIViewController, UIGestureRecognizerDel
private func prepareLeftViewController() { private func prepareLeftViewController() {
if let v: MaterialView = leftView { if let v: MaterialView = leftView {
leftViewController?.view.clipsToBounds = true leftViewController?.view.clipsToBounds = true
leftViewController?.view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
prepareViewControllerWithinContainer(leftViewController, container: v) prepareViewControllerWithinContainer(leftViewController, container: v)
} }
} }
...@@ -753,6 +754,7 @@ public class SideNavigationController : UIViewController, UIGestureRecognizerDel ...@@ -753,6 +754,7 @@ public class SideNavigationController : UIViewController, UIGestureRecognizerDel
private func prepareRightViewController() { private func prepareRightViewController() {
if let v: MaterialView = rightView { if let v: MaterialView = rightView {
rightViewController?.view.clipsToBounds = true rightViewController?.view.clipsToBounds = true
leftViewController?.view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
prepareViewControllerWithinContainer(rightViewController, container: v) prepareViewControllerWithinContainer(rightViewController, container: v)
} }
} }
......
...@@ -102,7 +102,7 @@ public class StatusBarViewController : UIViewController { ...@@ -102,7 +102,7 @@ public class StatusBarViewController : UIViewController {
self.rootViewController.removeFromParentViewController() self.rootViewController.removeFromParentViewController()
self.rootViewController = toViewController self.rootViewController = toViewController
self.rootViewController.view.clipsToBounds = true self.rootViewController.view.clipsToBounds = true
self.rootViewController.view.autoresizingMask = .FlexibleWidth self.rootViewController.view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
self.view.sendSubviewToBack(self.rootViewController.view) self.view.sendSubviewToBack(self.rootViewController.view)
completion?(result) completion?(result)
}) })
...@@ -142,7 +142,7 @@ public class StatusBarViewController : UIViewController { ...@@ -142,7 +142,7 @@ public class StatusBarViewController : UIViewController {
/// A method that prepares the rootViewController. /// A method that prepares the rootViewController.
private func prepareRootViewController() { private func prepareRootViewController() {
rootViewController.view.clipsToBounds = true rootViewController.view.clipsToBounds = true
rootViewController.view.autoresizingMask = .FlexibleWidth rootViewController.view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
prepareViewControllerWithinContainer(rootViewController, container: view) prepareViewControllerWithinContainer(rootViewController, container: view)
} }
......
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