{"id":13666943,"url":"https://github.com/macabeus/GridView","last_synced_at":"2025-04-26T15:31:51.848Z","repository":{"id":56913002,"uuid":"89896215","full_name":"macabeus/GridView","owner":"macabeus","description":"🌌 Apple TV | Amazing grid view in your tvOS/iOS app","archived":false,"fork":false,"pushed_at":"2017-07-23T07:07:36.000Z","size":1151,"stargazers_count":42,"open_issues_count":0,"forks_count":5,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-05T04:04:52.196Z","etag":null,"topics":["cocoapods","gridview","ios","stalkr-internals","tvos","uicollectionview"],"latest_commit_sha":null,"homepage":"https://cocoapods.org/pods/GridView","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/macabeus.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-05-01T04:05:22.000Z","updated_at":"2024-12-20T08:34:30.000Z","dependencies_parsed_at":"2022-08-20T20:10:06.609Z","dependency_job_id":null,"html_url":"https://github.com/macabeus/GridView","commit_stats":null,"previous_names":["brunomacabeusbr/gridview"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/macabeus%2FGridView","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/macabeus%2FGridView/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/macabeus%2FGridView/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/macabeus%2FGridView/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/macabeus","download_url":"https://codeload.github.com/macabeus/GridView/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251008677,"owners_count":21522153,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cocoapods","gridview","ios","stalkr-internals","tvos","uicollectionview"],"created_at":"2024-08-02T07:00:17.338Z","updated_at":"2025-04-26T15:31:51.424Z","avatar_url":"https://github.com/macabeus.png","language":"Swift","funding_links":[],"categories":["UIKit"],"sub_categories":[],"readme":"[![Version](https://img.shields.io/cocoapods/v/GridView.svg?style=flat)](http://cocoapods.org/pods/GridView)\n[![License](https://img.shields.io/cocoapods/l/GridView.svg?style=flat)](http://cocoapods.org/pods/GridView)\n[![Platform](https://img.shields.io/cocoapods/p/GridView.svg?style=flat)](http://cocoapods.org/pods/GridView)\n\n# GridView\n📜  Amazing grid view in your tvOS/iOS app\n\n![](http://i.imgur.com/Zn3c7bD.png)\n![](http://i.imgur.com/0fccFX3.png)\n\nYou can download this repository and see this example app.\n\n# How to use\n\n## Install\nIn `Podfile` add\n```\npod 'GridView'\n```\n\nand use `pod install`.\n\n## Setup\n\n### Storyboard\n![](http://i.imgur.com/nNbAekE.png)\n\n1. Create a *Container View*\n2. Change the *View Controller* for  *Collection View Controller*\n3. Set `GridViewController` as a custom class\n\n### Create a cell\n\nTo display a cell in grid, the cell need be a `UICollectionViewCell` and subscriber the protocol `SlotableCell`.\u003cbr\u003e\nAnd, you need create a xib file with *Collection View Cell*. The xib, and cell's indentifier in xib file, **need** have the same name of the class.\n\nMinimal example:\n\n```swift\nimport UIKit\nimport GridView\n\nclass CellLogs: UICollectionViewCell, SlotableCell {\n \n    static let slotWidth = 1 // size of cell in grid 📏\n    static let slotHeight = 1 // size of cell in grid 📐\n    var slotParams: [String : Any] = [:]\n\n    func load() { \n        // this method if called when a cell is created in grid 🔨\n    }\n}\n```\n\nWhen the grid will show the `CellLogs`, will get the `CellLogs.xib` and run the `load(params)` method.\n\n### Code\n\nYour controller that will manager a grid need subscriber the protocol `GridViewDelegate`\n\nMinimal example:\n\n```swift\nextension ViewController: GridViewDelegate {\n    func getCellToRegister() -\u003e [SlotableCell.Type] {\n        // we need register cell's class, then, send it's where 🖋\n        \n        return [CellLogs.self, CellMap.self]\n        \n        // if do you want list all classes that subscreber the SlotableCell protocol, you can read use this gist: https://gist.github.com/brunomacabeusbr/eea343bb9119b96eed3393e41dcda0c9 💜\n    }\n    \n    func setup(cell: SlotableCell) {\n        // this delegate is called in \"collectionView(_:cellForItemAt)\" from GridViewController\n        // it's useful when we need to setup many cells with same code 🍡\n        \n        // for example, connect to server, if a cell need\n        if let cellRealTime = cell as? CellRealTimeProtocol {\n            cellRealTime.connect()\n        }\n        \n        // layout\n        (cell as? UICollectionViewCell)?.layer.cornerRadius = 10\n    }\n}\n```\n\nThen, we need set a variable to manager a grid and set `ViewController` as a delegate.\n\nMinimal example:\n\n```swift\nclass ViewController: UIViewController {\n\n    @IBOutlet weak var container: UIView!\n    var containerGrid: GridViewController?\n    \n    override func viewDidLoad() {\n        super.viewDidLoad()\n        \n        // set the cells to show in grid 📌\n        containerGrid!.gridConfiguration = GridConfiguration.create(slots: Slots(slots: [\n            [Slot(cell: CellMap.self, params: [:]), Slot(cell: CellChart.self, params: [:])],\n            [Slot(cell: CellLogs.self, params: [:])],\n            [Slot(cell: CellCharacter.self, params: [\"race\": \"troll\"]), Slot(cell: CellCharacter.self, params: [\"race\": \"elves\"]), Slot(cell: CellCharacter.self, params: [\"race\": \"undead\"]), Slot(cell: CellCharacter.self, params: [\"race\": \"merfolk\"])]\n            ])\n        )\n    }\n\n    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {\n        \n        if segue.identifier == \"segueGrid\" {\n            self.containerGrid = (segue.destination as! GridViewController)\n            self.containerGrid!.delegate = self\n        }\n    }\n}\n```\n\nTo understand how to set layout with `gridConfiguration` correctly, read the section \"How GridView work?\".\n\n### params\n\nWhen you create a `Slot`, you set a cell of this slot, and also **params** of this slot. For example:\n\n```swift\nSlot(cell: CellCharacter.self, params: [\"race\": \"undead\"])\n```\n\nThe value of `params` is set in attribute `slotParams` of `SlotableCell`.\n\nExample of use:\n\n```swift\nclass CellCharacter: UICollectionViewCell, SlotableCell {\n    \n    ...\n    var slotParams: [String : Any] = [:]\n\n    func load() {\n        let paramRace = slotParams[\"race\"] as? String\n    \n        switch paramRace {\n        case \"undead\"?:\n            image.image = UIImage(named: \"undead\")!\n        case \"elves\"?:\n            image.image = UIImage(named: \"elves\")!\n        case \"troll\"?:\n            image.image = UIImage(named: \"troll\")!\n        default:\n            print(\"invalid race: \\(paramRace ?? \"nil\")\")\n        }\n    }\n}\n```\n\n### How to reload a grid?\n\nIf you already a set a value to `gridConfiguration`, and want set a new value, to reload a grid use the method `reloadGrid()`.\n\n```swift\ncontainerGrid!.gridConfiguration = [ ... ] // new values for my awesome grid\ncontainerGrid!.reloadGrid() // reload it\n```\n\n# How GridView work?\n\nThe GridView **always** show all cells, and set in each cell a proportional size with the `slotWidth` and `slotHeight`.\n\n![](http://i.imgur.com/Z6G8ymq.png)\n\nWhen GridView will draw a cell, check if have a enough space in first slot. If have, draw. If haven't, check in the second slot, and so on.\u003cbr\u003e\nThe total of columns is calculated at runtime.\n\n---\n\n**Maintainer**:\n\n\u003e [macabeus](http://macalogs.com.br/) \u0026nbsp;\u0026middot;\u0026nbsp;\n\u003e GitHub [@macabeus](https://github.com/macabeus)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmacabeus%2FGridView","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmacabeus%2FGridView","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmacabeus%2FGridView/lists"}