Code changes as per review comments.
This commit is contained in:
parent
7ba0d14c51
commit
ad345dacd8
@ -104,7 +104,6 @@ import Foundation
|
|||||||
}
|
}
|
||||||
|
|
||||||
func setFrame(with size: CGFloat) {
|
func setFrame(with size: CGFloat) {
|
||||||
progressBar.frame = CGRect(x: 0, y: 0, width: size, height: size)
|
|
||||||
widthConstraint?.constant = size
|
widthConstraint?.constant = size
|
||||||
setNeedsDisplay()
|
setNeedsDisplay()
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,6 +18,7 @@ open class Stars: View {
|
|||||||
}
|
}
|
||||||
private var delegateObject: MVMCoreUIDelegateObject?
|
private var delegateObject: MVMCoreUIDelegateObject?
|
||||||
private let itemSpacing: CGFloat = 3.0
|
private let itemSpacing: CGFloat = 3.0
|
||||||
|
private var heightConstraint: NSLayoutConstraint?
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Lifecycle
|
// MARK: - Lifecycle
|
||||||
@ -26,8 +27,9 @@ open class Stars: View {
|
|||||||
super.setupView()
|
super.setupView()
|
||||||
stack.translatesAutoresizingMaskIntoConstraints = false
|
stack.translatesAutoresizingMaskIntoConstraints = false
|
||||||
addSubview(stack)
|
addSubview(stack)
|
||||||
stack.topAnchor.constraint(equalTo: topAnchor).isActive = true
|
NSLayoutConstraint.pinView(toSuperview: stack, useMargins: true)
|
||||||
bottomAnchor.constraint(equalTo: stack.bottomAnchor).isActive = true
|
heightConstraint = heightAnchor.constraint(equalToConstant: 30)
|
||||||
|
heightConstraint?.isActive = true
|
||||||
stack.axis = .horizontal
|
stack.axis = .horizontal
|
||||||
stack.spacing = itemSpacing
|
stack.spacing = itemSpacing
|
||||||
}
|
}
|
||||||
@ -48,14 +50,13 @@ open class Stars: View {
|
|||||||
//------------------------------------------------------
|
//------------------------------------------------------
|
||||||
func createStar() {
|
func createStar() {
|
||||||
if let starsModel = starsModel {
|
if let starsModel = starsModel {
|
||||||
stack.subviews.forEach({$0.removeFromSuperview()})
|
|
||||||
let stars = starsModel.stars
|
let stars = starsModel.stars
|
||||||
|
let percentRequiredToFillStarFully = CGFloat(100/(starsModel.stars.count))
|
||||||
|
let numberOfFilledStars = Int(starsModel.percent/percentRequiredToFillStarFully)
|
||||||
for (index, starModel) in stars.enumerated() {
|
for (index, starModel) in stars.enumerated() {
|
||||||
let star = Star()
|
let star = Star()
|
||||||
|
|
||||||
//Fill the stars based on percentage. Ex: if there were 4 stars, 75 percent is 3 full stars
|
//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 {
|
if index < numberOfFilledStars {
|
||||||
starModel.percent = 100
|
starModel.percent = 100
|
||||||
} else if index == numberOfFilledStars {
|
} else if index == numberOfFilledStars {
|
||||||
@ -77,6 +78,12 @@ open class Stars: View {
|
|||||||
star.set(with: starModel, delegateObject, nil)
|
star.set(with: starModel, delegateObject, nil)
|
||||||
stack.addArrangedSubview(star)
|
stack.addArrangedSubview(star)
|
||||||
}
|
}
|
||||||
|
heightConstraint?.constant = starsModel.size
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override func reset() {
|
||||||
|
super.reset()
|
||||||
|
stack.subviews.forEach({$0.removeFromSuperview()})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user