So, if I write down the number one,2,3,….,16 within the share textfield, then share bar reveals completely in line with the share quantity. But when I exit the app, and re-open the app once more, any quantity all the way down to 16, share bar reveals 17%.
import UIKit
class GoalViewController: UIViewController, UITextFieldDelegate {
var titleLabel: UILabel!
var percentageLabel: UILabel!
var percentLabel: UILabel!
var percentageTextField: UITextField!
var progressView: UIProgressView!
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return .portrait
}
override func viewDidLoad() {
tremendous.viewDidLoad()
titleLabel = UILabel()
titleLabel.textual content = "Depend"
titleLabel.font = UIFont.boldSystemFont(ofSize: 40)
titleLabel.textColor = .white
titleLabel.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(titleLabel)
NSLayoutConstraint.activate([
titleLabel.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 0),
titleLabel.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor, constant: 20),
])
percentageLabel = UILabel()
percentageLabel.textual content = "Progress:"
percentageLabel.font = UIFont.boldSystemFont(ofSize: 20)
percentageLabel.textColor = .white
percentageLabel.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(percentageLabel)
NSLayoutConstraint.activate([
percentageLabel.topAnchor.constraint(equalTo: titleLabel.bottomAnchor, constant: 40),
percentageLabel.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor, constant: 20),
])
percentLabel = UILabel()
percentLabel.textual content = "%"
percentLabel.font = UIFont.boldSystemFont(ofSize: 20)
percentLabel.textColor = .white
percentLabel.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(percentLabel)
NSLayoutConstraint.activate([
percentLabel.topAnchor.constraint(equalTo: titleLabel.bottomAnchor, constant: 40),
percentLabel.leadingAnchor.constraint(equalTo: percentageLabel.trailingAnchor, constant: 60),
])
percentageTextField = UITextField()
percentageTextField.placeholder = "n"
percentageTextField.font = UIFont.systemFont(ofSize: 18)
percentageTextField.keyboardType = .numbersAndPunctuation
percentageTextField.borderStyle = .roundedRect
percentageTextField.translatesAutoresizingMaskIntoConstraints = false
percentageTextField.delegate = self
percentageTextField.textAlignment = .heart
percentageTextField.addTarget(self, motion: #selector(updateProgressBar), for: .editingDidEnd)
view.addSubview(percentageTextField)
NSLayoutConstraint.activate([
percentageTextField.centerYAnchor.constraint(equalTo: percentageLabel.centerYAnchor),
percentageTextField.leadingAnchor.constraint(equalTo: percentageLabel.trailingAnchor, constant: 10),
percentageTextField.widthAnchor.constraint(equalToConstant: 45),
])
if self.traitCollection.userInterfaceStyle == .darkish {
view.backgroundColor = .black
titleLabel.textColor = .white
percentageLabel.textColor = .white
percentLabel.textColor = .white
} else {
view.backgroundColor = .white
titleLabel.textColor = .black
percentageLabel.textColor = .black
percentLabel.textColor = .black
}
let progressView = UIProgressView(progressViewStyle: .default)
progressView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(progressView)
progressView.layer.cornerRadius = 10
progressView.tag = 100
progressView.layer.masksToBounds = true
progressView.layer.sublayers![1].cornerRadius = 10
progressView.subviews[1].clipsToBounds = true
progressView.layer.maskedCorners = [.layerMinXMinYCorner, .layerMaxXMinYCorner, .layerMinXMaxYCorner, .layerMaxXMaxYCorner]
NSLayoutConstraint.activate([
progressView.topAnchor.constraint(equalTo: titleLabel.bottomAnchor, constant: 85),
progressView.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor, constant: 20),
progressView.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor, constant: -20),
progressView.heightAnchor.constraint(equalToConstant: 30)
])
}
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
tremendous.traitCollectionDidChange(previousTraitCollection)
if self.traitCollection.userInterfaceStyle == .darkish {
view.backgroundColor = .black
titleLabel.textColor = .white
percentageLabel.textColor = .white
percentLabel.textColor = .white
} else {
view.backgroundColor = .white
titleLabel.textColor = .black
percentageLabel.textColor = .black
percentLabel.textColor = .black
}
}
override func viewDidLayoutSubviews() {
tremendous.viewDidLayoutSubviews()
if let progressView = view.subviews.first(the place: { $0 is UIProgressView }) as? UIProgressView {
progressView.layer.cornerRadius = 10
progressView.layer.masksToBounds = true
progressView.setNeedsLayout()
progressView.layoutIfNeeded()
}
}
override func viewWillAppear(_ animated: Bool) {
tremendous.viewWillAppear(animated)
updateProgressBar()
}
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
textField.resignFirstResponder()
return true
}
@objc func updateProgressBar() {
guard let percentageText = percentageTextField.textual content?.trimmingCharacters(in: .whitespacesAndNewlines),
let share = Float(percentageText) else {
return
}
let clampedPercentage = min(max(share, 0), 100)
if let progressView = view.viewWithTag(100) as? UIProgressView {
progressView.setProgress(clampedPercentage / 100.0, animated: true)
}
}
}
that is my code, please assist me!