react常用语法

本文介绍如何在React Native中获取DOM结构、设置图片作为背景及满屏显示的方法,并展示了如何同时应用多种样式。

1、获取dom结构

<div className="Component_projress"
             ref="projressBar"

js中:

let projressBar = this.refs.projressBar;

 2、将图片作为背景图

<Image
        source={require('./hello.jpg')} >
        <Text style={{fontSize: 50, color: 'red',}}>HELLO WORLD</Text>
      </Image>

内容写在 

Image 标签里面便可以。

3、将图片作为满屏
const styles = StyleSheet.create({
  backgroundImage:{
    flex:1,
    alignItems:'center',
    justifyContent:'center',
    width:null,
    height:null,
    //不加这句,就是按照屏幕高度自适应
    //加上这几,就是按照屏幕自适应
    //resizeMode:Image.resizeMode.contain,
    //祛除内部元素的白色背景
    backgroundColor:'rgba(0,0,0,0)',
  }
});

 4、使用多种样式

在标签上使用多个css样式的时候要用[]给括起来,并且行内样式的优先级大于StyleSheet定义的样式

style={[styles.button, {backgroundColor: this.props.bg}]

 

 

转载于:https://www.cnblogs.com/haonanZhang/p/7470751.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值