Last active
April 24, 2016 19:47
-
-
Save psaitu/0b88d9183fa3d677a147ffc0c12c2b14 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // AppDelegate.swift | |
| // SpotsPugs | |
| // | |
| // Created by Prabhu Saitu on 24/04/16. | |
| // Copyright © 2016 Prabhu Saitu. All rights reserved. | |
| // | |
| import UIKit | |
| import Spots | |
| import Brick | |
| enum Cell: String, StringConvertible { | |
| case Feed, FeaturedFeed, FeedDetail, Spot | |
| var string: String { | |
| return rawValue | |
| } | |
| } | |
| @UIApplicationMain | |
| class AppDelegate: UIResponder, UIApplicationDelegate { | |
| var window: UIWindow? | |
| var navigationController: UINavigationController? | |
| func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { | |
| // Override point for customization after application launch. | |
| window = UIWindow(frame: UIScreen.mainScreen().bounds) | |
| SpotsController.configure = { | |
| $0.backgroundColor = UIColor.clearColor() | |
| } | |
| GridSpot.configure = { collectionView, layout in | |
| // layout.sectionInset = UIEdgeInsets(top: 10, left: 10, bottom: 20, right: 10) | |
| // layout.minimumInteritemSpacing = 5 | |
| // layout.minimumLineSpacing = 10 | |
| } | |
| GridSpot.defaultView = GridSpotCell.self | |
| let pugs = Component(title: "Pugs", items: [ | |
| ViewModel(image: "http://25.media.tumblr.com/tumblr_lized8bWxD1qaa50yo1_500.jpg"), | |
| ViewModel(image: "http://27.media.tumblr.com/tumblr_lrvd8i2yMT1qd4jfno1_500.jpg"), | |
| ViewModel(image: "http://30.media.tumblr.com/tumblr_liic7bdmRF1qcipjro1_500.jpg"), | |
| ViewModel(image: "http://25.media.tumblr.com/tumblr_lsigg3D23h1qz9wudo1_500.jpg") | |
| ]) | |
| let pugsSpot = GridSpot(component: pugs) | |
| let controller = MainViewController(title: "Pugs", spots:[pugsSpot]) | |
| let navigationController = UINavigationController(rootViewController: controller) | |
| window?.rootViewController = navigationController | |
| window?.makeKeyAndVisible() | |
| return true | |
| } | |
| func applicationWillResignActive(application: UIApplication) { | |
| // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. | |
| // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. | |
| } | |
| func applicationDidEnterBackground(application: UIApplication) { | |
| // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. | |
| // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. | |
| } | |
| func applicationWillEnterForeground(application: UIApplication) { | |
| // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. | |
| } | |
| func applicationDidBecomeActive(application: UIApplication) { | |
| // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. | |
| } | |
| func applicationWillTerminate(application: UIApplication) { | |
| // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. | |
| } | |
| } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // GridSpotCell.swift | |
| // SpotsPugs | |
| // | |
| // Created by Prabhu Saitu on 24/04/16. | |
| // Copyright © 2016 Prabhu Saitu. All rights reserved. | |
| // | |
| import UIKit | |
| import Imaginary | |
| import Spots | |
| import Brick | |
| class GridSpotCell: UICollectionViewCell, SpotConfigurable { | |
| var size = CGSize(width: 120, height: 120) | |
| lazy var imageView: UIImageView = { | |
| let imageView = UIImageView() | |
| imageView.contentMode = .ScaleAspectFill | |
| imageView.autoresizingMask = [.FlexibleWidth, .FlexibleBottomMargin] | |
| return imageView | |
| }() | |
| override init(frame: CGRect) { | |
| super.init(frame: frame) | |
| contentView.addSubview(imageView) | |
| } | |
| required init?(coder aDecoder: NSCoder) { | |
| fatalError("init(coder:) has not been implemented") | |
| } | |
| func configure(inout item: ViewModel) { | |
| optimize() | |
| if !item.image.isEmpty { | |
| imageView.frame = CGRect(x: 0, y: 0, width: size.width, height: size.height) | |
| imageView.image = nil | |
| let URL = NSURL(string: item.image) | |
| imageView.setImage(URL) | |
| } | |
| layoutSubviews() | |
| } | |
| override func layoutSubviews() { | |
| super.layoutSubviews() | |
| imageView.frame = CGRect(x: 0, y: 0, width: size.width, height: size.height) | |
| imageView.height = 120 | |
| imageView.width = 120 | |
| imageView.clipsToBounds = true | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // ViewController.swift | |
| // SpotsPugs | |
| // | |
| // Created by Prabhu Saitu on 24/04/16. | |
| // Copyright © 2016 Prabhu Saitu. All rights reserved. | |
| // | |
| import UIKit | |
| import Spots | |
| import Brick | |
| class MainViewController: SpotsController { | |
| convenience init(title: String, spots:[Spotable]) { | |
| self.init(spots:spots) | |
| self.title = title | |
| } | |
| override func viewDidLoad() { | |
| super.viewDidLoad() | |
| // Do any additional setup after loading the view, typically from a nib. | |
| } | |
| override func didReceiveMemoryWarning() { | |
| super.didReceiveMemoryWarning() | |
| // Dispose of any resources that can be recreated. | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment