Okay... so I probably might have done this all wrong in my code then. For my ProgressTracker, I made a custom UIView class called ProgressTrackerView. At the basic level, a progress tracker has the following components:
1. Progress Element (A circular UIImageView with an image for each "stage" of a multi step task)
2. Progress Line (A UIView that connects two progress elements together)
For my progress element, I have the following method:
func makeProgressElementAt(x: CGFloat, forDirection : Direction) {
/** Making a progress element */
let progressElement = UIImageView(frame: CGRect(x: x - progressElementWidth/2,
y: self.bounds.midY - progressElementHeight/2,
width: progressElementWidth,
height: progressElementHeight))
/** Change the corner radius to make the imageView a circle */
progressElement.layer.cornerRadius = progressElementWidth/2
/** Add the newly made line subview */
addSubview(progressElement)
/** TODO: Documentation */
if (direction == .left) {
progressElements.insert(progressElement, at: 0)
} else {
progressElements.append(progressElement)
}
}
For my progress lines, I have a method like this:
/**
* Makes a new line according to the direction passed in
*
* - Note: This method will become private in a future code review.
*
*/
func makeLine(forDirection direction: Direction) {
var x: CGFloat = 0
/** TODO: Documentation */
// A line can be drawn to the left of an element or to the right of an element or a line
// can be in the center and elements are drawn on either side of it...
switch direction {
case.left:
x = leftLineAnchor - lineWidth
leftLineAnchor = x
break
case.right:
x = rightLineAnchor
rightLineAnchor = x + lineWidth
break
default:
x = self.bounds.midX - lineWidth/2
leftLineAnchor = x
rightLineAnchor = self.bounds.midX + lineWidth/2
}
/** Making a line */
let line = UIView(frame: CGRect(x: x,
y: self.bounds.midY - lineHeight/2,
width: lineWidth,
height: lineHeight))
/** Color the line */
line.backgroundColor = defaultLineColor
/** Add the newly made line subview */
addSubview(line)
/** TODO: Documentation */
if (direction == .left) {
lines.insert(line, at: 0)
} else {
lines.append(line)
}
}
Then I have several methods, but the main is is drawProgressTracker in which the elements are generated based on the number of stages for task, the appropriate images are placed, etc, after which I calle my draw method below:
override func draw(_ rect: CGRect) {
progressElements = []
lines = []
drawProgressTracker()
}
Would this probably be better to discuss over email @QuinceyMorris...I've written a fair bit of code, it's pretty well documented, but its a lot... I dont know how much I would have to re-write or tweak to make this correctly work.