gpt4 book ai didi

ios - 如何在 react-native (iOS) 中创建一个离散 slider ?

转载 作者:行者123 更新时间:2023-11-29 12:12:39 27 4
gpt4 key购买 nike

我的 react-native 应用程序中有一个 slider 组件,它使用最小值/最大值属性和 onValueChange 中的一些舍入很好地限制为 1-5 的离散值:

<View>
<Text style={styles.text} >
{this.state.value}
</Text>
<SliderIOS
ref='slider'
style={styles.slider}
value={1}
minimumValue={1}
maximumValue={5}
onValueChange={(value) => {
this.setState({
value: Math.round(value)
});
}}
/>
</View>

我想要的是 slider handle 按钮捕捉到离散位置 1、2、3、4、5,而不是沿着 slider 连续移动。提示表示赞赏!

最佳答案

供将来引用:SliderIOS 在此期间已被弃用,应该使用 Slider 组件。 <Slider>带有一个步骤属性:

Step value of the slider. The value should be between 0 and (maximumValue - minimumValue). Default value is 0.

所以具体问题的解决方案就是简单地设置

<Slider
step={1}
...
/>

关于ios - 如何在 react-native (iOS) 中创建一个离散 slider ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32911434/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com