Commit b5da540b by Daniel Dahan

working copy of BottomNavigationBar with App example project

parent 5c193224
......@@ -41,7 +41,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
let bottomNavigationController: BottomNavigationController = BottomNavigationController()
bottomNavigationController.viewControllers = [AppMenuViewController(rootViewController: AppNavigationController(rootViewController: RecipesViewController())), VideoViewController(), PhotoViewController()]
bottomNavigationController.selectedIndex = 0
bottomNavigationController.tabBar.tintColor = MaterialColor.lightBlue.base
bottomNavigationController.tabBar.tintColor = MaterialColor.white
bottomNavigationController.tabBar.backgroundColor = MaterialColor.grey.darken4
// Override point for customization after application launch.
......
......@@ -154,10 +154,9 @@ class AppMenuViewController: MenuViewController {
/// Prepare tabBarItem.
private func prepareTabBarItem() {
tabBarItem.title = "Recipes"
tabBarItem.image = MaterialIcon.photoLibrary
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 {
/// NavigationBar share button.
private var shareButton: FlatButton!
/// MaterialCollectionView.
private var collectionView: MaterialCollectionView!
/// MaterialScrollView.
private var scrollView: UIScrollView!
/// Image thumbnail height.
private var thumbnailHieght: CGFloat = 300
/// Image height for the imageCardView.
private var imageHeight: CGFloat = 300
override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
......@@ -72,12 +72,21 @@ class ItemViewController: UIViewController {
prepareTitleLabel()
prepareShareButton()
prepareNavigationBar()
prepareScrollView()
prepareImageCardView()
}
/// Handler for shareButton.
internal func handleShareButton() {
print("Share Button Pressed")
override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
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() {
......@@ -108,20 +117,24 @@ class ItemViewController: UIViewController {
shareButton.pulseColor = MaterialColor.white
shareButton.setImage(image, forState: .Normal)
shareButton.setImage(image, forState: .Highlighted)
shareButton.addTarget(self, action: #selector(handleShareButton), forControlEvents: .TouchUpInside)
}
/// Prepares view.
/// Prepares the navigationItem.
private func prepareNavigationBar() {
navigationItem.titleLabel = titleLabel
navigationItem.detailLabel = detailLabel
navigationItem.rightControls = [shareButton]
}
/// Prepares the scrollView.
private func prepareScrollView() {
scrollView = UIScrollView(frame: view.bounds)
view.addSubview(scrollView)
}
/// Prepares the imageCardView.
private func prepareImageCardView() {
if let data: Dictionary<String, AnyObject> = dataSource.data as? Dictionary<String, AnyObject> {
let height: CGFloat = 300
imageCardView = ImageCardView()
......@@ -136,7 +149,7 @@ class ItemViewController: UIViewController {
imageCardView.titleLabel?.text = data["title"] as? String
imageCardView.titleLabel?.textColor = MaterialColor.grey.darken4
imageCardView.titleLabel?.font = RobotoFont.regularWithSize(20)
imageCardView.titleLabelInset.top = height
imageCardView.titleLabelInset.top = imageHeight
let detailLabel: UILabel = UILabel()
detailLabel.text = data["detail"] as? String
......@@ -148,14 +161,12 @@ class ItemViewController: UIViewController {
imageCardView.detailViewInset.top = 52
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
}
view.addSubview(imageCardView)
scrollView.addSubview(imageCardView)
imageCardView.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.alignFromTop(view, child: imageCardView)
MaterialLayout.alignToParentHorizontally(view, child: imageCardView)
}
}
}
......@@ -57,9 +57,8 @@ class PhotoViewController: UIViewController {
/// Prepare tabBarItem.
private func prepareTabBarItem() {
tabBarItem.title = "Photo"
tabBarItem.image = MaterialIcon.photoCamera
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 {
"date": "February 26, 2016",
"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 {
searchButton.addTarget(self, action: #selector(handleSearchButton), forControlEvents: .TouchUpInside)
}
/// Prepares the NavigationBar.
/// Prepares the navigationItem.
private func prepareNavigationBar() {
navigationItem.titleLabel = titleLabel
navigationItem.leftControls = [menuButton]
......
......@@ -57,9 +57,8 @@ class VideoViewController: UIViewController {
/// Prepare tabBarItem.
private func prepareTabBarItem() {
tabBarItem.title = "Video"
tabBarItem.image = MaterialIcon.videocam
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 {
self.rootViewController.removeFromParentViewController()
self.rootViewController = toViewController
self.rootViewController.view.clipsToBounds = true
self.rootViewController.view.autoresizingMask = .FlexibleWidth
self.rootViewController.view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
self.view.sendSubviewToBack(self.rootViewController.view)
completion?(result)
})
......@@ -169,7 +169,7 @@ public class MenuViewController : UIViewController {
/// A method that prepares the rootViewController.
private func prepareRootViewController() {
rootViewController.view.clipsToBounds = true
rootViewController.view.autoresizingMask = .FlexibleWidth
rootViewController.view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
prepareViewControllerWithinContainer(rootViewController, container: view)
}
......
......@@ -349,7 +349,7 @@ public class SideNavigationController : UIViewController, UIGestureRecognizerDel
self.rootViewController.removeFromParentViewController()
self.rootViewController = toViewController
self.rootViewController.view.clipsToBounds = true
self.rootViewController.view.autoresizingMask = .FlexibleWidth
self.rootViewController.view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
self.view.sendSubviewToBack(self.rootViewController.view)
completion?(result)
})
......@@ -737,7 +737,7 @@ public class SideNavigationController : UIViewController, UIGestureRecognizerDel
/// A method that prepares the rootViewController.
private func prepareRootViewController() {
rootViewController.view.clipsToBounds = true
rootViewController.view.autoresizingMask = .FlexibleWidth
rootViewController.view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
prepareViewControllerWithinContainer(rootViewController, container: view)
}
......@@ -745,6 +745,7 @@ public class SideNavigationController : UIViewController, UIGestureRecognizerDel
private func prepareLeftViewController() {
if let v: MaterialView = leftView {
leftViewController?.view.clipsToBounds = true
leftViewController?.view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
prepareViewControllerWithinContainer(leftViewController, container: v)
}
}
......@@ -753,6 +754,7 @@ public class SideNavigationController : UIViewController, UIGestureRecognizerDel
private func prepareRightViewController() {
if let v: MaterialView = rightView {
rightViewController?.view.clipsToBounds = true
leftViewController?.view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
prepareViewControllerWithinContainer(rightViewController, container: v)
}
}
......
......@@ -102,7 +102,7 @@ public class StatusBarViewController : UIViewController {
self.rootViewController.removeFromParentViewController()
self.rootViewController = toViewController
self.rootViewController.view.clipsToBounds = true
self.rootViewController.view.autoresizingMask = .FlexibleWidth
self.rootViewController.view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
self.view.sendSubviewToBack(self.rootViewController.view)
completion?(result)
})
......@@ -142,7 +142,7 @@ public class StatusBarViewController : UIViewController {
/// A method that prepares the rootViewController.
private func prepareRootViewController() {
rootViewController.view.clipsToBounds = true
rootViewController.view.autoresizingMask = .FlexibleWidth
rootViewController.view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
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