-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTableViewCell.swift
More file actions
54 lines (42 loc) · 1.79 KB
/
TableViewCell.swift
File metadata and controls
54 lines (42 loc) · 1.79 KB
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
//
// TableViewCell.swift
// DemoSwift
//
// Created by Chandan Singh on 28/02/17.
// Copyright © 2017 Chandan Singh. All rights reserved.
//
import UIKit
class TableViewCell: UITableViewCell {
@IBOutlet weak var collectionView: UICollectionView!
var listSongs: [String]!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
func getRandomColor() -> UIColor{
let randomRed:CGFloat = CGFloat(drand48())
let randomGreen:CGFloat = CGFloat(drand48())
let randomBlue:CGFloat = CGFloat(drand48())
return UIColor(red: randomRed, green: randomGreen, blue: randomBlue, alpha: 1.0)
}
}
extension TableViewCell : UICollectionViewDataSource,UICollectionViewDelegateFlowLayout {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 5
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath) as! CollectionViewCell
cell.imageView.backgroundColor = self.getRandomColor()
cell.lblName.text = self.listSongs[indexPath.row]
return cell
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let itemWidth = collectionView.bounds.width / 3.0
let itemHeight = self.frame.height - 10
return CGSize(width: itemWidth, height: itemHeight)
}
}