2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy
4 | of this software and associated documentation files (the "Software"), to deal
5 | in the Software without restriction, including without limitation the rights
6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 | copies of the Software, and to permit persons to whom the Software is
8 | furnished to do so, subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in
11 | all copies or substantial portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 | THE SOFTWARE.
20 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 | With GridTimerView you can show a schedule with timer controller. Each cell can manage multiple events with different durations. It's perfect for listing TV programs shows in a simulated table. And the good news is that you can customise most of these features with your own fonts, colors, sizes... and many more.
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 | # GridTimerView
47 |
48 | - [x] Show multiple events for each cell
49 | - [x] Totally customizable
50 | - [x] Smooth scrolling experience
51 | - [x] Easy usage
52 | - [x] Supports iOS, developed in Swift 4
53 |
54 |
55 | ## Table of Contents
56 |
57 | - [Usage](#usage)
58 | - [UIView in your xib / storyboard](#uiviewinyourxib/storyboard)
59 | - [Configuration](#configuration)
60 | - [DataSource](#datasource)
61 | - [Delegates](#delegates)
62 | - [Extra](#extra)
63 | - [Installation](#installation)
64 | - [Author](#author)
65 | - [License](#license)
66 |
67 | ## Usage
68 |
69 | It is important to know that this pod is composed of rows. Each row has a set of events with start time and end time of type date. You must create a custom view to show in each row.
70 |
71 | Once you've installed this pod, you can follow next steps. It's really simple:
72 |
73 | ### UIView in your xib / storyboard
74 |
75 | Add a `UIView` in the xib where you want to place GridTimerView. Then you have to input the class name in the view, you can change this in the identity inspector of the interface builder. Remember to input `GridTimerView` in both (Class & Module)
76 |
77 |
78 |
79 | Then, connect the IBOutlet in your UIViewController
80 |
81 | ```swift
82 | @IBOutlet weak var gridTimerView: GridTimerView!
83 | ```
84 |
85 | ### Make your custom item row (required)
86 |
87 | Make your own custom item subclassing `UIView`. Then you can use it in DataSource protocol.
88 |
89 | ### Implement datasource and delegate
90 |
91 | The first way to customize this `GridTimerView` is implementing delegate and datasource methods. These methods handle the most common use cases.
92 |
93 | ```swift
94 | gridTimerView.dataSource = self
95 | gridTimerView.delegate = self
96 | ```
97 |
98 | ### Configuration
99 |
100 | You can setup `GridTimerView`with your own parameters. See default values:
101 |
102 | ```swift
103 | var configuration = GridTimerConfiguration()
104 |
105 | // Font for timer labels in rule
106 | configuration.ruleFont = UIFont.systemFont(ofSize: 10, weight: .semibold)
107 |
108 | // Color for timer labels in rule
109 | configuration.ruleTextColor = UIColor.lightGray
110 |
111 | // Days before today for initial time
112 | configuration.ruleDaysFrom = 1
113 |
114 | // Days after today for end time
115 | configuration.ruleDaysTo = 2
116 |
117 | // Rule ticks color
118 | configuration.ruleTicksColor = UIColor.white
119 |
120 | // Rule background color
121 | configuration.ruleBackgroundColor = UIColor.darkGray
122 |
123 | // Font used in current time
124 | configuration.timerFont = UIFont.systemFont(ofSize: 12, weight: .semibold)
125 |
126 | // Background color used in current time
127 | configuration.timerColor = UIColor.blue
128 |
129 | // Text color used in current time
130 | configuration.timerTextColor = UIColor.white
131 |
132 | // Selected date line color
133 | configuration.lineColor = UIColor.blue
134 |
135 | // Current date line color
136 | configuration.currentTimeLineColor = UIColor.blue
137 |
138 | /// Current date line dashed
139 | configuration.currentTimeLineDashed = false
140 |
141 | // Selected highlight color on event
142 | configuration.selectedItemColor = UIColor.blue
143 |
144 | // Unselected color on event
145 | configuration.unselectedItemColor = UIColor.lightGray
146 |
147 | /// Selected highlight color when row cell touched
148 | configuration.selectedColorOnTouch = UIColor.init(red: 0.95, green: 0.95, blue: 0.95, alpha: 1)
149 |
150 | // Row separation
151 | configuration.rowSeparation = 10.0
152 |
153 | /// Enable refresh control when dragged down
154 | configuration.enableRefresh = false
155 | ```
156 |
157 | Is important to finally assign configuration to `GridTimerView`
158 |
159 | ```swift
160 | gridTimerView.configuration = configuration
161 | ```
162 |
163 | ### DataSource
164 |
165 | Is needed to show your own cells with events in collection table.
166 |
167 | ```swift
168 | // Needed for displaying rows. Returns number of rows in the table
169 | func numberOfRows(inGridTimerView gridTimerView: GridTimerView) -> Int
170 |
171 | // Needed for displaying rows. Returns height of custom row in the table
172 | func heightForRow(inGridTimerView gridTimerView: GridTimerView) -> CGFloat
173 |
174 | // Needed for displaying items in the timeline row. Returns height of highlighted items
175 | func heightForTimelineRow(inGridTimerView gridTimerView: GridTimerView) -> CGFloat
176 |
177 | // Needed for displaying items in the timeline row. Returns number of items in row
178 | func gridTimerView(gridTimerView: GridTimerView, numberOfItemsAtRowIndex rowIndex: Int) -> Int
179 |
180 | // Needed for drawing your custom row with item index and row index
181 | func gridTimerView(gridTimerView: GridTimerView, viewForItemIndex itemIndex: Int, inRowIndex rowIndex: Int) -> UIView {
182 |
183 | let channelView = ChannelView()
184 | let channel = channels[rowIndex]
185 | var viewModel = ChannelView.ViewModel()
186 |
187 | if channel.events.count > 0 {
188 | viewModel.title = channel.events[itemIndex].title
189 | viewModel.subtitle = channel.events[itemIndex].subtitle
190 | viewModel.image = channel.channelImage
191 | }
192 |
193 | channelView.viewModel = viewModel
194 | return channelView
195 | }
196 |
197 | // Needed for drawing item in the timeline row
198 | func gridTimerView(gridTimerView: GridTimerView, startTimeForItemIndex itemIndex: Int, inRowIndex rowIndex: Int) -> Date
199 |
200 | // Needed for drawing item in the timeline row
201 | func gridTimerView(gridTimerView: GridTimerView, endTimeForItemIndex itemIndex: Int, inRowIndex rowIndex: Int) -> Date
202 |
203 | // Returns color by item in row.
204 | // If returns nil, `selectedItemColor` in configuration will be the selected color
205 | func gridTimerView(gridTimerView: GridTimerView, colorForItemIndex itemIndex: Int, inRowIndex rowIndex: Int) -> UIColor?
206 | ```
207 |
208 | ### Delegates
209 |
210 | In order to add more functionality in your app, you must implement te `GridTimerViewDelegate` and set delegate to your view controller instance.
211 |
212 | ```swift
213 | // Called when item is highlighted.
214 | func gridTimerView(gridTimerView: GridTimerView, didHighlightAtItemIndex itemIndex: Int, inRowIndex rowIndex: Int)
215 |
216 | // Called when row is selected
217 | func gridTimerView(gridTimerView: GridTimerView, didSelectRowAtIndex rowIndex: Int)
218 |
219 | // Called when you refresh the table
220 | func didPullToRefresh(inGridTimerView gridTimerView: GridTimerView)
221 | ```
222 |
223 | ### Extra
224 |
225 | You can also use next methods for scrolling timer, registering and reuse your custom view row or end refreshing table when new data has loaded.
226 |
227 | ```swift
228 | // Scroll the timer to single date programatically
229 | func scrollToDate(date: Date)
230 |
231 | // Obtain your custom view
232 | func viewForRowIndex(rowIndex: Int) -> UIView?
233 |
234 | // End refreshing table. Used when finish loading data
235 | func endRefresh()
236 |
237 | // Reload collection view data
238 | func reloadGridData()
239 |
240 | // Reload collection view data for row index
241 | func reloadGridRowIndex(_ rowIndex: Int)
242 | ```
243 |
244 |
245 | ## Installation
246 |
247 | **GridTimerView** is available through [CocoaPods](https://cocoapods.org). To install
248 | it, simply add the following line to your Podfile:
249 |
250 | ```ruby
251 | pod 'GridTimerView'
252 | ```
253 |
254 | ## Author
255 |
256 | Alberto Aznar, info@alberdev.com
257 |
258 | ## License
259 |
260 | GridTimerView is available under the MIT liceßnse. See the LICENSE file for more info.
261 |
262 | ## Libraries by @alberdev
263 |
264 |
265 |
266 |
267 |
268 |
269 |
270 |
271 |
--------------------------------------------------------------------------------