Skip to content

Instantly share code, notes, and snippets.

@ycui1
Created January 10, 2020 02:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ycui1/4ebef87c11fe55d2ac5b7406e54d775a to your computer and use it in GitHub Desktop.
Save ycui1/4ebef87c11fe55d2ac5b7406e54d775a to your computer and use it in GitHub Desktop.
import UIKit
class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
let tableView = UITableView()
let tasks = [
Task(id: "S_1001", name: "Laundry", description: "Wash all the clothes.", tagColor: .blue),
Task(id: "S_1002", name: "Pick up kids", description: "Pick up the kids from the school.", tagColor: .red),
Task(id: "S_1003", name: "Walk the dog", description: "Walk the dog in the morning", tagColor: .green),
Task(id: "S_1004", name: "Yoga class", description: "The yoga class begins at 5 pm.", tagColor: .purple)
]
override func viewDidLoad() {
super.viewDidLoad()
tableView.frame = UIScreen.main.bounds
view.addSubview(tableView)
tableView.delegate = self
tableView.dataSource = self
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return tasks.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
let task = tasks[indexPath.row]
cell.imageView?.image = UIImage(systemName: "circle.fill")?.withRenderingMode(.alwaysTemplate)
cell.imageView?.tintColor = task.tagColor
cell.textLabel?.text = task.name
return cell
}
}
struct Task {
let id: String
let name: String
let description: String
var tagColor: UIColor
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment