日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

react-native?實現漸變色背景過程_React

作者:Volon?Kou ? 更新時間: 2022-11-07 編程語言

react-native 漸變色背景

使用react-native-linear-gradient插件

1.安裝

npm react-native-linear-gradient

2.鏈接

react-native link react-native-linear-gradient

3.代碼使用

 <LinearGradient colors={["#57AFFF","#2A63BF","#042289"]} style={{flex:1}}>
 </LinearGradient>

4.效果圖

5.如果出現以下錯誤

解決辦法:

1.徹底退出項目重新react-native run-ios就可以了。

2.如果1沒解決,就嘗試2

react-native學習記錄

滾動條

橫向滾動:

//在ScrollView里面加上這段代碼即可
?horizontal={true}

隱藏滾動條:

//隱藏水平
showsHorizontalScrollIndicator = {false}
//隱藏垂直
showsVerticalScrollIndicator = {false}

輪播圖示例

先導入:

$ npm install react-native-swiper --save
$ npm i react-timer-mixin --save
import React, {Component} from 'react';
import {
? ? StyleSheet,
? ? View,
? ? Image,
} from 'react-native';
import Dimensions from 'Dimensions';
import Swiper from 'react-native-swiper';
var screenWidth = Dimensions.get('window').width;
export default class SwiperScreen extends Component {
? ? render() {
? ? ? ? return (
? ? ? ? ? ? <View style={styles.lunbotu}>
? ? ? ? ? ? ? ? <Swiper
? ? ? ? ? ? ? ? ? ? style={styles.wrapper}
? ? ? ? ? ? ? ? ? ? height={240}
? ? ? ? ? ? ? ? ? ? autoplay={true}
? ? ? ? ? ? ? ? ? ? loop={true}
? ? ? ? ? ? ? ? ? ? keyExtractor={(item, index) => index + ''}
? ? ? ? ? ? ? ? ? ? index={1}
? ? ? ? ? ? ? ? ? ? autoplayTimeout={3}
? ? ? ? ? ? ? ? ? ? horizontal={true}
? ? ? ? ? ? ? ? ? ? onMomentumScrollEnd={(e, state, context) => {
? ? ? ? ? ? ? ? ? ? }}
? ? ? ? ? ? ? ? ? ? dot={<View style={styles.dotStyle}/>}
? ? ? ? ? ? ? ? ? ? activeDot={<View style={styles.activeDotStyle}/>}
? ? ? ? ? ? ? ? ? ? paginationStyle={{
? ? ? ? ? ? ? ? ? ? ? ? bottom: 10
? ? ? ? ? ? ? ? ? ? }}>
? ? ? ? ? ? ? ? ? ? <View>
? ? ? ? ? ? ? ? ? ? ? ? <Image style={{width: screenWidth, height: 150}}
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?resizeMode="stretch"
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?source={{uri: ''}}>
? ? ? ? ? ? ? ? ? ? ? ? </Image>
? ? ? ? ? ? ? ? ? ? </View>
? ? ? ? ? ? ? ? ? ? <View>
? ? ? ? ? ? ? ? ? ? ? ? <Image style={{width: screenWidth, height: 150}}
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?resizeMode="stretch"
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?source={{uri: ''}}>
? ? ? ? ? ? ? ? ? ? ? ? </Image>
? ? ? ? ? ? ? ? ? ? </View>
? ? ? ? ? ? ? ? ? ? <View>
? ? ? ? ? ? ? ? ? ? ? ? <Image style={{width: screenWidth, height: 150}}
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?resizeMode="stretch"
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?source={{uri: ''}}>
? ? ? ? ? ? ? ? ? ? ? ? </Image>
? ? ? ? ? ? ? ? ? ? </View>
? ? ? ? ? ? ? ? </Swiper>
? ? ? ? ? ? </View>
? ? ? ? );
? ? }
}
const styles = StyleSheet.create({
? ? dotStyle: {
? ? ? ? width: 22,
? ? ? ? height: 3,
? ? ? ? backgroundColor: '#fff',
? ? ? ? opacity: 0.4,
? ? ? ? borderRadius: 0,
? ? },
? ? activeDotStyle: {
? ? ? ? width: 22,
? ? ? ? height: 3,
? ? ? ? backgroundColor: '#fff',
? ? ? ? borderRadius: 0,
? ? },
? ? lunbotu: {
? ? ? ? height: 120,
? ? ? ? backgroundColor: '#222222'
? ? },
});

漸變色

先安裝:

?yarn add react-native-linear-gradient
?react-native link react-native-linear-gradient
import React, {Component} from 'react';
import {
? ? Image,
? ? View,
? ? Text,
? ? StyleSheet
} from 'react-native';
import LinearGradient from "react-native-linear-gradient";
export default class LinearGradientScreen extends Component {
? ? render() {
? ? ? ? return (
? ? ? ? ? ? <View style={{height: '100%'}}>
? ? ? ? ? ? ? ? <LinearGradient colors={['red', 'green', 'blue']} style={styles.container}>
? ? ? ? ? ? ? ? </LinearGradient>
? ? ? ? ? ? </View>
? ? ? ? );
? ? }
}
const styles = StyleSheet.create({
? ? container: {
? ? ? ? height: '100%'
? ? }
})

ScrollableTabView默認頁面

標簽內加上initialPage并賦值下標即可

render() {
? ? return (
? ? ? ? <ScrollableTabView
? ? ? ? ? ? initialPage={1}>
? ? ? ? ? ? <Text tabLabel='Tab 1'>Tab 1</Text>
? ? ? ? ? ? <Text tabLabel='Tab 2'>Tab 2</Text>
? ? ? ? ? ? <Text tabLabel='Tab 3'>Tab 3</Text>
? ? ? ? </ScrollableTabView>
? ? );
}

ScrollableTabView背景顏色

標簽內加上tabBarBackgroundColor并賦值即可

render() {
? ? return (
? ? ? ? <ScrollableTabView
? ? ? ? ? ? tabBarBackgroundColor='#FFFFFF'>
? ? ? ? ? ? <Text tabLabel='Tab 1'>Tab 1</Text>
? ? ? ? ? ? <Text tabLabel='Tab 2'>Tab 2</Text>
? ? ? ? ? ? <Text tabLabel='Tab 3'>Tab 3</Text>
? ? ? ? </ScrollableTabView>
? ? );
}

ScrollableTabView選中顏色

標簽內加上tabBarActiveTextColor并賦值即可

render() {
? ? return (
? ? ? ? <ScrollableTabView
? ? ? ? ? ? tabBarActiveTextColor='#FFFFFF'>
? ? ? ? ? ? <Text tabLabel='Tab 1'>Tab 1</Text>
? ? ? ? ? ? <Text tabLabel='Tab 2'>Tab 2</Text>
? ? ? ? ? ? <Text tabLabel='Tab 3'>Tab 3</Text>
? ? ? ? </ScrollableTabView>
? ? );
}

ScrollableTabView未選中顏色

標簽內加上tabBarInactiveTextColor并賦值即可

render() {
? ? return (
? ? ? ? <ScrollableTabView
? ? ? ? ? ? tabBarInactiveTextColor ='#FFFFFF'>
? ? ? ? ? ? <Text tabLabel='Tab 1'>Tab 1</Text>
? ? ? ? ? ? <Text tabLabel='Tab 2'>Tab 2</Text>
? ? ? ? ? ? <Text tabLabel='Tab 3'>Tab 3</Text>
? ? ? ? </ScrollableTabView>
? ? );
}

原文鏈接:https://blog.csdn.net/koufulong/article/details/81779323

欄目分類
最近更新