react-native - 在 React Native 中浮动到 Int
问题描述
我仍然是反应原生的新手。我希望你们能帮助我。我想在滑块中将 float 更改为 int 。(在 onValueChange 中)
这是我的代码:
<Section style={{padding:10, backgroundColor:'white', borderRadius:10, marginTop:30}}>
<Block xsSize='1/2' smSize='1/2'>
<Slider
style={{width: 200, height: 40}}
minimumValue={1}
maximumValue={100}
minimumTrackTintColor="#0197ca"
maximumTrackTintColor="#a2a2a2"
onValueChange={(value) => this.setState({sliderState:value})}
/>
</Block>
<Block xsSize='1/2' smSize='1/2' style={{padding:10, borderRadius:5, backgroundColor:'#0197ca', width:60, position:'relative', left:90}}>
<Text style={{color:'white'}}>{this.state.sliderState}%</Text>
</Block>
</Section>
我想将输出更改为<Text style={{color:'white'}}>{this.state.sliderState}%</Text>
int。现在,输出仍然是浮动的。
解决方案
当您希望值以某种方式出现时,请确保在设置状态时进行更改。
这样,您就可以按照您想要的方式格式化您的值。
试试这个:
<Section style={{padding:10, backgroundColor:'white', borderRadius:10, marginTop:30}}>
<Block xsSize='1/2' smSize='1/2'>
<Slider
style={{width: 200, height: 40}}
minimumValue={1}
maximumValue={100}
minimumTrackTintColor="#0197ca"
maximumTrackTintColor="#a2a2a2"
onValueChange={(value) =>this.setState({sliderState:Math.round(value)})}
/>
</Block>
<Block
xsSize='1/2'
smSize='1/2'
style={{padding:10, borderRadius:5, backgroundColor:'#0197ca', width:60, position:'relative', left:90}}>
<Text style={{color:'white'}}>
{this.state.sliderState}%
</Text>
</Block>
</Section>
推荐阅读
- jolie - 使用 Jolie 存储工作流状态
- linux - 如何在mongodb中将数据库从一台服务器复制到另一台服务器
- json - 如何在 couchbase 数组中搜索特定字符串
- xml - XSLT 的 document() 函数的 TWIG 等价物是什么?
- c++ - 如果从使用 Poco/Timer 启动的线程进行日志记录,则 Poco HTTPServer 中止
- java - 我可以在我的 java 应用程序上为 config.yml 指定默认值吗?
- node.js - db.createRole 与 Mongoose
- jquery - 不使用 id 标签的 jquery 选择器
- python - 使用python2提取firefox历史记录
- phalcon - 在 Phalcon\Mailer 中使用邮件模板的布局