Code changes as per review comments.

This commit is contained in:
Lekshmi S 2020-10-06 13:06:31 +05:30
parent 7ba0d14c51
commit ad345dacd8
2 changed files with 12 additions and 6 deletions

View File

@ -104,7 +104,6 @@ import Foundation
}
func setFrame(with size: CGFloat) {
progressBar.frame = CGRect(x: 0, y: 0, width: size, height: size)
widthConstraint?.constant = size
setNeedsDisplay()
}

View File

@ -18,6 +18,7 @@ open class Stars: View {
}
private var delegateObject: MVMCoreUIDelegateObject?
private let itemSpacing: CGFloat = 3.0
private var heightConstraint: NSLayoutConstraint?
//--------------------------------------------------
// MARK: - Lifecycle
@ -26,8 +27,9 @@ open class Stars: View {
super.setupView()
stack.translatesAutoresizingMaskIntoConstraints = false
addSubview(stack)
stack.topAnchor.constraint(equalTo: topAnchor).isActive = true
bottomAnchor.constraint(equalTo: stack.bottomAnchor).isActive = true
NSLayoutConstraint.pinView(toSuperview: stack, useMargins: true)
heightConstraint = heightAnchor.constraint(equalToConstant: 30)
heightConstraint?.isActive = true
stack.axis = .horizontal
stack.spacing = itemSpacing
}
@ -48,14 +50,13 @@ open class Stars: View {
//------------------------------------------------------
func createStar() {
if let starsModel = starsModel {
stack.subviews.forEach({$0.removeFromSuperview()})
let stars = starsModel.stars
let percentRequiredToFillStarFully = CGFloat(100/(starsModel.stars.count))
let numberOfFilledStars = Int(starsModel.percent/percentRequiredToFillStarFully)
for (index, starModel) in stars.enumerated() {
let star = Star()
//Fill the stars based on percentage. Ex: if there were 4 stars, 75 percent is 3 full stars
let percentRequiredToFillStarFully = CGFloat(100/(starsModel.stars.count))
let numberOfFilledStars = Int(starsModel.percent/percentRequiredToFillStarFully)
if index < numberOfFilledStars {
starModel.percent = 100
} else if index == numberOfFilledStars {
@ -77,6 +78,12 @@ open class Stars: View {
star.set(with: starModel, delegateObject, nil)
stack.addArrangedSubview(star)
}
heightConstraint?.constant = starsModel.size
}
}
public override func reset() {
super.reset()
stack.subviews.forEach({$0.removeFromSuperview()})
}
}