-
Notifications
You must be signed in to change notification settings - Fork 0
/
ViewController.swift
executable file
·211 lines (128 loc) · 7.04 KB
/
ViewController.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
//
// ViewController.swift
// LiveTVAppStoreScratch
//
// Created by Shashwat Singh on 3/9/17.
// Copyright © 2017 Shashanoid. All rights reserved.
//
import UIKit
class CategoryController: UICollectionViewController, UICollectionViewDelegateFlowLayout, UINavigationBarDelegate{
fileprivate let cellId = "cellId"
fileprivate let largeCellId = "largeCellId"
override func viewDidLoad() {
super.viewDidLoad()
collectionView?.backgroundColor = UIColor.white
collectionView?.register(CategoryCell.self, forCellWithReuseIdentifier: "cellId")
collectionView?.register(LargeCategoryCell.self, forCellWithReuseIdentifier: largeCellId)
collectionView?.register(FirstLargeCell.self, forCellWithReuseIdentifier: "FirstCellID")
navigationItem.title = "Card Store"
let height: CGFloat = 75
let navbar = UINavigationBar(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: height))
navbar.backgroundColor = UIColor.white
navbar.delegate = self as! UINavigationBarDelegate
let navItem = UINavigationItem()
navItem.title = "Card Store"
navItem.leftBarButtonItem = UIBarButtonItem(title: "Close", style: .plain, target: self, action: #selector(closestore))
navItem.rightBarButtonItem = UIBarButtonItem(title: "Edit Card", style: .plain, target: self, action: #selector(setname))
navbar.items = [navItem]
view.addSubview(navbar)
collectionView?.frame = CGRect(x: 0, y: height, width: UIScreen.main.bounds.width, height: (UIScreen.main.bounds.height - height))
navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Back", style: .plain, target: self, action: #selector(help))
}
func closestore(){
dismiss(animated: true, completion: nil)
}
func setname(){
// let data = Bundle.main.loadNibNamed("CardListViewController", owner: self, options: nil) as! CardListViewController
}
func help(){
}
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 4
}
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if indexPath.item == 0{
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: largeCellId, for: indexPath) as! LargeCategoryCell
cell.featuredAppsController = self
return cell
}
if indexPath.item == 2{
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "FirstCellID", for: indexPath) as! FirstLargeCell
cell.featuredAppsController = self
return cell
}
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cellId", for: indexPath) as! CategoryCell
cell.featuredAppsController = self
if indexPath.item == 2 {
cell.nameLabel.text = "Editor's Choice"
}
if indexPath.item == 3 {
cell.nameLabel.text = "Recommended For You"
}
return cell
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
if indexPath.item == 0{
return CGSize(width: view.frame.width, height: 160)
}
return CGSize(width: view.frame.width, height: 180)
}
}
class FirstLargeCell: FirstSectionCell {
private let largeCellId = "LargeAppcellId"
override func setupviews() {
super.setupviews()
appsCollectionView.register(LargeAppCell.self, forCellWithReuseIdentifier: "LargeAppcellId")
}
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: largeCellId , for: indexPath) as! CategoryInfoCell
cell.nameLabel.text = categories?[indexPath.item].name
cell.priceLabel.text = categories?[indexPath.item].language
cell.category = categories?[indexPath.item]
return cell
}
override func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
if frame.width > 600{
return CGSize(width: 400, height: frame.height - 7)
}
return CGSize(width: frame.width - 40, height: frame.height - 7)
}
class LargeAppCell: CategoryInfoCell{
override func setupviews() {
imageView.translatesAutoresizingMaskIntoConstraints = false
imageView.layer.cornerRadius = 10
addSubview(imageView)
addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|[v0]|", options: NSLayoutFormatOptions(), metrics: nil, views: ["v0":imageView]))
addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|[v0]|", options: NSLayoutFormatOptions(), metrics: nil, views: ["v0":imageView]))
}
}
}
class LargeCategoryCell: BannerCell {
private let largeCellId = "LargeAppcellId"
override func setupviews() {
super.setupviews()
appsCollectionView.register(LargeAppCell.self, forCellWithReuseIdentifier: "LargeAppcellId")
}
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: largeCellId , for: indexPath) as! CategoryInfoCell
cell.nameLabel.text = categories?[indexPath.item].name
cell.priceLabel.text = categories?[indexPath.item].language
cell.category = categories?[indexPath.item]
return cell
}
override func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
if frame.width > 600{
return CGSize(width: 400, height: frame.height - 7)
}
return CGSize(width: frame.width - 40, height: frame.height - 7)
}
class LargeAppCell: CategoryInfoCell{
override func setupviews() {
imageView.translatesAutoresizingMaskIntoConstraints = false
imageView.layer.cornerRadius = 10
addSubview(imageView)
addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|[v0]|", options: NSLayoutFormatOptions(), metrics: nil, views: ["v0":imageView]))
addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|[v0]|", options: NSLayoutFormatOptions(), metrics: nil, views: ["v0":imageView]))
}
}
}