【问题标题】:How can we design Arrow card in react-native我们如何在 react-native 中设计箭头卡
【发布时间】:2018-06-11 19:05:25
【问题描述】:

我正在开发一个示例应用程序,在此应用程序中需要使用箭头卡,它用于提供显示卡。 我尝试了基于 react-native 形状,但我没有得到输出。

假设如果提供的文本自动增加,箭头设计形状也会增加

这是我的代码:

<View style={styles.container}>
                <View style={{ flex: 0.1, backgroundColor: "blue" }} />
                <View
                    style={{
                        flex: 0.9,
                        backgroundColor: "green",
                        justifyContent: "center",
                        alignItems: "center"
                    }}
                >
                    <View style={styles.baseTop} />
                    <View style={styles.baseBottom} />
                </View>
            </View>
baseTop: {
    borderBottomWidth: 35,
    borderBottomColor: "red",
    borderLeftWidth: 50,
    borderLeftColor: "transparent",
    borderRightWidth: 50,
    borderRightColor: "transparent",
    height: 0,
    width: 0,
    left: 0,
    top: -35,
    position: "absolute"
},
baseBottom: {
    backgroundColor: "red",
    height: 55,
    width: 100
}

这个我需要像这种类型的图片,这里是引用图片:

【问题讨论】:

  • 我建议您在问题中添加“css”标签。

标签: css react-native react-native-android react-native-ios


【解决方案1】:

这就是我实现与您的图像几乎相同的方式。

import React, { Component } from 'react';
import { Text, View,StyleSheet } from "react-native";

export default class App extends Component {
  render() {
       return (
           <View style={{flex:1}}>
             <View
                style={styles.wrapper}>
                <View style={styles.rectangle}><Text>6</Text> <Text>tens</Text> </View>
                <View style={styles.rectangle}><Text>6</Text> <Text>ones</Text> </View>>
                 <View style={styles.triangle}></View>

            </View>
           </View>
        );
  }
}

const styles = StyleSheet.create({
    wrapper: {
        flexDirection: "row",
        justifyContent: "flex-start",
        flex: 0.2,
        alignItems: "center",
        paddingLeft: 29,
        paddingTop: 0,
        marginTop: 0

    },
    rectangle: {
        width: 50,
        backgroundColor: "yellow",
        margin: 0,
        justifyContent: "center",
        alignItems: "center",
        height: 52,
        borderColor:"black"

    },
    triangle: {
        width: 0,
        height: 0,
        backgroundColor: 'transparent',
        borderStyle: 'solid',
        borderLeftWidth: 27,
        borderRightWidth: 27,
        borderBottomWidth: 43,
        borderLeftColor: 'transparent',
        borderRightColor: 'transparent',
        borderBottomColor:"yellow",
        transform: [
            { rotate: '90deg' }
        ],
        margin: 0,
        marginLeft: -6,
        borderWidth: 0,
        borderColor:"black"
    }
});

博览链接https://snack.expo.io/rycpKiAe7

【讨论】:

  • 嗨,谢谢,但我没有得到边框黑线。我也需要黑色边框怎么办?
【解决方案2】:

您可以制作一个 flex square,使用 Transform 旋转它,然后将其绝对定位到正确的位置。

或者您可以使用react-native-svg 并创建一个 SVG,然后相应地定位它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-02-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-13
    • 2022-01-21
    • 1970-01-01
    相关资源
    最近更新 更多