diff --git a/iOSTemplate/Base.lproj/Main.storyboard b/iOSTemplate/Base.lproj/Main.storyboard index 6460871fafc9edccce13e263aa2e480f414ae42b..3b682d356a8ef87dad479cf6553b3954dbd6ce3a 100644 --- a/iOSTemplate/Base.lproj/Main.storyboard +++ b/iOSTemplate/Base.lproj/Main.storyboard @@ -18,8 +18,8 @@ - - + + diff --git a/iOSTemplate/RatingControl.swift b/iOSTemplate/RatingControl.swift index ab218bec37e3b06826bd19d1652e2d3bcd8b77b8..400d1947ea6bc5db3ba853c946362b7bb0a83c89 100644 --- a/iOSTemplate/RatingControl.swift +++ b/iOSTemplate/RatingControl.swift @@ -7,7 +7,22 @@ import UIKit -class RatingControl: UIStackView { +@IBDesignable class RatingControl: UIStackView { + + // MARK: Properties + private var ratingButtons = [UIButton]() + @IBInspectable var starSize: CGSize = CGSize(width: 44.0, height: 44.0) { + didSet { + setupButtons() + } + } + + @IBInspectable var starCount: Int = 5 { + didSet { + setupButtons() + } + } + var rating = 0 // MARK: Initialization override init(frame: CGRect) { @@ -27,20 +42,32 @@ class RatingControl: UIStackView { // MARK: Private Methods private func setupButtons() { - // Create the button - let button = UIButton() - button.backgroundColor = UIColor.red - - // Add constraints - button.translatesAutoresizingMaskIntoConstraints = false - button.heightAnchor.constraint(equalToConstant: 44.0).isActive = true - button.widthAnchor.constraint(equalToConstant: 44.0).isActive = true - - // Setup the button action - button.addTarget(self, action: #selector(RatingControl.ratingButtonTapped(button:)), for: .touchUpInside) + // clear any existing buttons + for button in ratingButtons { + removeArrangedSubview(button) + button.removeFromSuperview() + } + ratingButtons.removeAll() - // Add the button to the stack - addArrangedSubview(button) + for _ in 0..