Skip to content

Commit

Permalink
Add animating option to max value
Browse files Browse the repository at this point in the history
  • Loading branch information
woin2ee committed Jun 6, 2024
1 parent a0160a3 commit f6d6f8e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 10 deletions.
5 changes: 5 additions & 0 deletions Sources/UIKitPlus/RoundedProgressView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ open class RoundedProgressView: UIView {
private var _max: Int = 0 {
didSet {
setNeedsLayout()
if isAnimating {
UIView.animate(withDuration: 0.3) {
self.layoutIfNeeded()
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,33 @@ final class RoundedProgressViewExampleViewController: UIViewController {
$0.text = "Animation :"
}

lazy var animationOnOffSwitch = UISwitch().then {
$0.isOn = progressBar.isAnimating
lazy var animationOnOffSwitch = UISwitch().then { `switch` in
`switch`.isOn = progressBar.isAnimating
`switch`.addAction(
UIAction { [weak self] _ in
guard let self else { return }
self.progressBar.isAnimating = `switch`.isOn
},
for: .valueChanged
)
}

let maxValueLabel = UILabel().then {
$0.text = "Max value :"
}

lazy var maxValueTextField = UITextField().then { textField in
textField.text = "\(progressBar.max)"
textField.borderStyle = .roundedRect
textField.addAction(
UIAction { [weak self] _ in
guard let maxValue = Int(textField.text ?? "") else {
return
}
self?.progressBar.max = maxValue
},
for: .allEditingEvents
)
}

override func viewDidLoad() {
Expand All @@ -56,14 +81,8 @@ final class RoundedProgressViewExampleViewController: UIViewController {
view.addSubview(upButton)
view.addSubview(animationOnOffLabel)
view.addSubview(animationOnOffSwitch)

animationOnOffSwitch.addAction(
UIAction { [weak self] _ in
guard let self else { return }
self.progressBar.isAnimating = self.animationOnOffSwitch.isOn
},
for: .valueChanged
)
view.addSubview(maxValueLabel)
view.addSubview(maxValueTextField)
}

override func viewDidLayoutSubviews() {
Expand All @@ -74,5 +93,7 @@ final class RoundedProgressViewExampleViewController: UIViewController {
upButton.pin.vCenter(100).hCenter(50).sizeToFit()
animationOnOffLabel.pin.vCenter(200).hCenter(-50).sizeToFit()
animationOnOffSwitch.pin.vCenter(200).hCenter(50).sizeToFit()
maxValueLabel.pin.vCenter(250).hCenter(-50).sizeToFit()
maxValueTextField.pin.vCenter(250).hCenter(50).width(120).sizeToFit()
}
}

0 comments on commit f6d6f8e

Please sign in to comment.