简体   繁体   English

如何在IOS设备中垂直对齐图标?

[英]How to align Icon vertically in IOS devices?

I want to align this options icon inside the TouchableHighlight in IOS application in react-native but when I implement it is not using textAlignVerticle property as it is android only property. 我想在react-native中的IOS应用程序中的TouchableHighlight中对齐此选项图标,但是当我实现它时,它不使用textAlignVerticle属性,因为它是仅android属性。 How I can get the alternative which works both in android and IOS? 如何获得在Android和IOS上均可使用的替代方案?

 <TouchableHighlight style={[{position: 'absolute', bottom: 20, zIndex:999999, right: 155, borderRadius: 25}, (this.state.searchList)? { backgroundColor: 'red' }: {backgroundColor: 'black'}]} onPress={()=>this.props.navigation.navigate('SearchSetting')} > <Icon name="options" style={{height: 50, width: 50, color: 'white', textAlign: 'center', textAlignVertical: 'center'}} /> </TouchableHighlight> 

A component of react native is using the flexbox algorithm (very same with CSS Flexbox). react native的一个组成部分是使用flexbox算法(与CSS Flexbox完全相同)。 So you can put any child component to the vertically or horizontally align using justifyContent and alignItems in parent component. 因此,您可以使用父组件中的justifyContentalignItems将任何子组件垂直或水平对齐。 Both justifyContent and alignItems are depends on flexDirection . justifyContentalignItems都取决于flexDirection The default flexDirection is column in react native. 默认的flexDirection是react native中的column

In flexDirection: 'row'; flexDirection: 'row';

You can align child component to the vertically for justifyContent and horizontally for alignItems in parent component. 您可以在子组件中将子组件与justifyContent垂直justifyContent ,在父组件justifyContent与水平alignItems

Try with below code: 尝试以下代码:

<TouchableHighlight  
  style={[
    { 
      position: 'absolute', 
      bottom: 20, 
      zIndex:999999, 
      right: 155, 
      borderRadius: 25,
      backgroundColor: '#0000ff'
     }
  ]}>

  <View 
    style={{
      flex: 1,
      width: 100,
      height: 100,
      justifyContent: 'center',
      alignItems: 'center'
    }}>
    <Ionicons name="ios-home" size={20} color={'#FFF'} />
  </View>
</TouchableHighlight>

I don't know what icon component are you using. 我不知道您使用的是哪个图标组件。 I'm using react-native-vector-icons . 我正在使用react-native-vector-icons So I don't need to set width and height in style props of icon component for icon size. 因此,我不需要在图标组件的样式道具中为图标大小设置widthheight

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

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