網站首頁 編程語言 正文
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
相關推薦
- 2022-05-25 Springboot使用Redis-Cell實現限流
- 2022-12-29 Android?Fragment的具體使用方式詳解_Android
- 2022-04-09 python中IO流和對象序列化詳解_python
- 2022-02-09 C++學習之IO流(輸入輸出流)詳解_C 語言
- 2023-12-25 fiddler展示接口的響應時間
- 2022-08-17 React-Route6實現keep-alive效果_React
- 2022-09-13 Python運算符的應用超全面詳細教程_python
- 2022-09-30 react中useState使用:如何實現在當前表格直接更改數據_React
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支