Archived
Added icons for substitution plan courses
This commit is contained in:
@@ -12,7 +12,7 @@ import Alamofire
|
||||
import SQLite3
|
||||
|
||||
class FirstViewController : UIViewController, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
|
||||
|
||||
|
||||
let reuseIdentifier = "cell"
|
||||
@IBOutlet weak var collectionView: UICollectionView!
|
||||
let queue = DispatchQueue(label: "work-queue")
|
||||
@@ -46,6 +46,7 @@ class FirstViewController : UIViewController, UICollectionViewDataSource, UIColl
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
|
||||
collectionView.backgroundColor = UIColor(red: 0.8, green: 0.8, blue: 0.8, alpha: 1.0)
|
||||
|
||||
// let layout = collectionView.collectionViewLayout as! UICollectionViewFlowLayout
|
||||
@@ -68,18 +69,96 @@ class FirstViewController : UIViewController, UICollectionViewDataSource, UIColl
|
||||
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath as IndexPath) as! CollectionViewCell
|
||||
if self.group.count != 0 {
|
||||
cell.group.text = self.group[indexPath.item]
|
||||
cell.course.text = self.course[indexPath.item]
|
||||
cell.additional.text = self.additional[indexPath.item]
|
||||
cell.date.text = self.date[indexPath.item]
|
||||
cell.time.text = self.time[indexPath.item]
|
||||
cell.room.text = self.room[indexPath.item]
|
||||
|
||||
let course = self.course[indexPath.item]
|
||||
let image = getImage(from: course)
|
||||
|
||||
if image != nil {
|
||||
let attachment: NSTextAttachment = NSTextAttachment()
|
||||
attachment.bounds = CGRect(x: 0, y: 0, width: cell.course.frame.height - 6, height: cell.course.frame.height - 6)
|
||||
attachment.image = image
|
||||
|
||||
let courseImage = NSMutableAttributedString(attachment: attachment)
|
||||
let courseString = NSAttributedString(string: " " + course)
|
||||
courseImage.append(courseString)
|
||||
|
||||
cell.course.attributedText = courseImage
|
||||
} else {
|
||||
cell.course.text = course
|
||||
}
|
||||
}
|
||||
|
||||
// cell.courseIcon.frame = CGRect(x: 0, y: 0, width: cell.course.frame.height, height: cell.course.frame.height)
|
||||
|
||||
// cell.backgroundColor = UIColor(red: 0.39, green: 0.71, blue: 0.96, alpha: 1.0)
|
||||
cell.backgroundColor = UIColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)
|
||||
cell.tintView.backgroundColor = cell.backgroundColor
|
||||
return cell
|
||||
}
|
||||
|
||||
func getImage(from icon: String) -> UIImage? {
|
||||
var imagePath = ""
|
||||
let i = icon.lowercased()
|
||||
if i.contains("deu") || i.contains("dep") || i.contains("daz") {
|
||||
imagePath = "ic_german"
|
||||
} else if i.contains("mat") || i.contains("map") {
|
||||
imagePath = "ic_maths"
|
||||
} else if i.contains("eng") || i.contains("enp") || i.contains("ena") {
|
||||
imagePath = "ic_english"
|
||||
} else if i.contains("spo") || i.contains("spp") || i.contains("spth") {
|
||||
imagePath = "ic_pe"
|
||||
} else if i.contains("pol") || i.contains("pop") {
|
||||
imagePath = "ic_politics"
|
||||
} else if i.contains("dar") || i.contains("dap") {
|
||||
imagePath = "ic_drama"
|
||||
} else if i.contains("phy") || i.contains("php") {
|
||||
imagePath = "ic_physics"
|
||||
} else if i.contains("bio") || i.contains("bip") || i.contains("nw") {
|
||||
imagePath = "ic_biology"
|
||||
} else if i.contains("che") || i.contains("chp") {
|
||||
imagePath = "ic_chemistry"
|
||||
} else if i.contains("phi") || i.contains("psp") {
|
||||
imagePath = "ic_philosophy"
|
||||
} else if i.contains("laa") || i.contains("laf") || i.contains("lat") {
|
||||
imagePath = "ic_latin"
|
||||
} else if i.contains("spa") || i.contains("spf") {
|
||||
imagePath = "ic_spanish"
|
||||
} else if i.contains("fra") || i.contains("frf") || i.contains("frz") {
|
||||
imagePath = "ic_french"
|
||||
} else if i.contains("inf") {
|
||||
imagePath = "ic_compsci"
|
||||
} else if i.contains("ges") {
|
||||
imagePath = "ic_history"
|
||||
} else if i.contains("rel") {
|
||||
imagePath = "ic_religion"
|
||||
} else if i.contains("geg") || i.contains("wuk") {
|
||||
imagePath = "ic_geography"
|
||||
} else if i.contains("kun") {
|
||||
imagePath = "ic_arts"
|
||||
} else if i.contains("mus") {
|
||||
imagePath = "ic_music"
|
||||
} else if i.contains("tue") {
|
||||
imagePath = "ic_turkish"
|
||||
} else if i.contains("chi") {
|
||||
imagePath = "ic_chinese"
|
||||
} else if i.contains("gll") {
|
||||
imagePath = "ic_gll"
|
||||
} else if i.contains("wat") {
|
||||
imagePath = "ic_wat"
|
||||
} else if i.contains("för") {
|
||||
imagePath = "ic_help"
|
||||
} else if i.contains("wp") || i.contains("met") {
|
||||
imagePath = "ic_pencil"
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
return UIImage(named: imagePath)
|
||||
}
|
||||
|
||||
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
||||
print("You selected cell#\(indexPath.item)!")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user