如何在ReactNative中将货币图标放在TextInput的值前面?

问题描述 投票:0回答:1

当用户输入金额时,我需要将货币图标放在值的前面,但这并不容易。我花了一整天,但仍然找不到理想的解决方案。我最好的方法是将子组件包装到TextInput中,如下所示:

          <TextInput
            style={[SS.input, styles.input, props.styleInput, iErrored, iFocused, iDisabled]}
            placeholder={props.placeholder}
            underlineColorAndroid='transparent' editable={!props.disabled}
            keyboardType={keyboardType} autoCapitalize='none'
            autoCorrect={false} selection={state.position}
            value={state.value} onChangeText={this._onChangeText}
            onFocus={this._onFocus} onBlur={this._onBlur}
            autoFocus={autoFocus}>
            {!!this.props.icon && !!state.value && (
              <Text style={{marginLeft: 10}}>{this.props.icon}</Text>
            )}
          </TextInput>

但是此决定有几个缺点。第一个不可能设置子组件的样式,我不能从数量上设置左填充。第二个是紧随图标之后的TextInput的焦点。有人可以帮我吗。enter image description here

javascript css react-native stylesheet textinput
1个回答
0
投票

我相信您正在寻找的是CSS ::after伪元素。这是一个使用contenteditable span的示例:

#money {
  border: 1px solid black;
  padding: 2px 4px;
}

#money::after {
  content: " €";
}
<span id="money" contenteditable="true"></span>
© www.soinside.com 2019 - 2024. All rights reserved.