IOS Programmer IOS Programmer - 1 year ago 128
Swift Question

How to make UILabel show the UISlider value?

I've tried to make a slider to show a percentage out of 100, but the label doesn't show that value correctly.

Answer Source

A UISlider has a default min and max of 0 and 1. So the slider is sending all kinds of fractional values as you move the slider such as 0.153343 and .53453545, etc. But you convert that number to an Int. That leaves you with only 0 and 1.

Either multiply the sender.value * 100 or change the slider's max value to 100.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download