简体   繁体   English

如何在iOS中将滑块值转换为整数?

[英]How to convert slider value to integer in ios?

How to convert float from 0..1 to integer 0 to 255 in xcode for ios? 如何在iOS的Xcode中将float从0..1转换为0到255的整数? thanx! 谢谢!

float number = [slider value];
int value = (int)(number * 255)

The value property of a UISlider is always a float . UISlidervalue属性始终是float In addition to Nico's answer, you could also set the bounds on the slider to what you want by 除了Nico的答案外,您还可以将滑块的边界设置为所需的范围

[slider setMinimumValue:0.0];
[slider setMaximumValue:255.0];

Then, whenever you call slider.value , cast to an int by 然后,当你调用slider.value ,强制转换为int

(int)slider.value
int value = (int)([slider value] * 255)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM