简体   繁体   English

React-Native 复选框样式

[英]React-Native checkbox styling

I'm using CheckBox from the react-native for react-native project.我将 react-native 中的 CheckBox 用于 react-native 项目。

I want to change the style to the following image.我想将样式更改为下图。 But there is no specific way to change the但是没有具体的方法可以改变在此处输入图像描述 mark inside the checkbox.在复选框内标记。

I'm not an expert UI developer to implement this style.我不是实施这种风格的专业 UI 开发人员。 I tried different solutions to fix this styling issue, but I still can not fix it.我尝试了不同的解决方案来解决此样式问题,但仍然无法解决。 Please help me to find a solution for this.请帮助我找到解决方案。 Thanks in advance.提前致谢。

Expected Checkbox UI:预期的复选框用户界面:

在此处输入图像描述

available UI with my stylings:具有我的样式的可用 UI:

在此处输入图像描述

Code and Styles as below.代码和Styles如下。

    import { CheckBox } from 'react-native';

    <CheckBox
     value={isItemSelected}
     onValueChange={() => [setItemSelection(!isItemSelected), 
 categorySelectHandler(item.category_name, !isItemSelected)]}
     style={styles.checkbox}
     onFillColor={"#C4C4C4"}
     color={'#FF8300'} />
    
    checkbox: {
     alignSelf: "center",
     borderRadius: 10,
     borderColor: '#C4C4C4',
    },

Use @react-native-community/checkbox for customisation.使用@react-native-community/checkbox进行定制。

import CheckBox from '@react-native-community/checkbox';
          <CheckBox
            // disabled={disabled}
            offAnimationType="stroke"
            // onChange={() => setIsOpen(!isOpen)}
            onFillColor={'blue'}
            onCheckColor={'white'}
            // value={checked}
            boxType="square"
            style={styles.checkbox}
           />

Instead of using react-native-checkbox you can create a custom checkbox component that will work in the same way.您可以创建一个以相同方式工作的自定义复选框组件,而不是使用 react-native-checkbox。 You just have to use the checked image and the uncheck image for that and wrap it inside the Pressable.您只需要为此使用已选中的图像和未选中的图像并将其包装在 Pressable 中。 For example:例如:

const [checked,setChecked] = useState(false);
<Pressable onPress={()=>setChecked(!checked)}>
   <Image source={checked?checkedImage:unCheckedImage} />
</Pressable>

where checked and unChecked images are the one you will import.其中选中和未选中的图像是您要导入的图像。

Try this Library npm i react-native-check-box,试试这个库 npm i react-native-check-box,

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

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