all. I can't figure out this one. I'm working on an app that needs to have this view as a TableView (representing excercises, with the excercise name as header) and inside each cell I need to see and be able to touch these rounded buttons (representing sets as number of buttons and reps as number inside the buttons). I've been able to put images and that in CollectionView but no clue for buttons. Here is a sketch I've made.
https://i.stack.imgur.com/ke6rt.png
My tableViewController
import Foundation
import UIKit
class WorkoutViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = #colorLiteral(red: 0.2156862745, green: 0.368627451, blue: 0.5921568627, alpha: 1)
}
var workouts: [Workout1] = Workout1.fetchWorkout1()
override func numberOfSections(in tableView: UITableView) -> Int {
return workouts.count
}
override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return "ExcerciseName"
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return workouts.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "workoutCell", for: indexPath)
let workout = workouts[indexPath.row]
cell.textLabel?.text = workout.excerciseName
cell.textLabel?.textColor = UIColor.white
return cell
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let workout = workouts[indexPath.row]
tableView.deselectRow(at: indexPath, animated: true)
print("Do \(workout.sets) sets of \(workout.reps) reps of \(workout.excerciseName)")
}
override func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
cell.backgroundColor = UIColor.clear
}
}
The source of the data
struct Workout1 {
let excerciseName: String
let sets: Int
let reps: Int
static func fetchWorkout1() -> [Workout1] {
let w1 = Workout1(excerciseName: "Bench Press", sets: 3, reps: 8)
let w2 = Workout1(excerciseName: "Push Press", sets: 3, reps: 8)
let w3 = Workout1(excerciseName: "Squat", sets: 3, reps: 8)
let w4 = Workout1(excerciseName: "Deadlift", sets: 3, reps: 8)
let w5 = Workout1(excerciseName: "Bicep Curl", sets: 3, reps: 8)
let w6 = Workout1(excerciseName: "Tricep Pushdown", sets: 3, reps: 8)
return [w1,w2,w3,w4,w5,w6]
}
}