Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Troubles with starting value using UISlider

Started working on the application. There was the following problem, in Main.storyboard the current value is set for the slider (for the top one it is 1.5 out of 3, and for the bottom one it is 100 out of 200), therefore, in the screenshot, I should have points on the slider track in the middle. I started googling about it, I can't find anything. Xcode 12 problem maybe? If not, please help me write the correct search query. I will be very grateful. Sorry for my bad English. :)

Here ViewController:

import UIKit

class ViewController: UIViewController {

    @IBOutlet weak var heightLabel: UILabel!
    @IBOutlet weak var weightLabel: UILabel!

    override func viewDidLoad() {
        super.viewDidLoad()

    }
    
    @IBAction func heightSliderChanged(_ sender: UISlider) {
        print(sender.value)
        heightLabel.text = String(format: "%.2f", sender.value) + "m"
    }

    @IBAction func weightSliderChanged(_ sender: UISlider) {
        weightLabel.text = String(format: "%.0f", sender.value) + "Kg"
    }
    
}

Property's for first slider:

Property's for first slider

Property's for second slider:

Property's for second slider

like image 240
TDMNS Avatar asked Dec 13 '20 09:12

TDMNS


1 Answers

Yes, it's Xcode issues. You can find the issues list from this link. (https://fahimfarook.medium.com/xcode-12-and-ios-14-developer-bugs-and-issues-ada35920a104).

Create an outlet of both slider and set value through coding.

@IBOutlet weak var firstSlider: UISlider!
@IBOutlet weak var secondSlider: UISlider!

override func viewDidLoad() {
    super.viewDidLoad()
    
    firstSlider.minimumValue = 0
    firstSlider.maximumValue = 3
    firstSlider.value = 1.5
    
    secondSlider.minimumValue = 0
    secondSlider.maximumValue = 200
    secondSlider.value = 100
}
like image 131
Raja Kishan Avatar answered Oct 17 '22 00:10

Raja Kishan