【React Native开发】React Native控件之WebView组件详解以及实
转载请标明出处: http://www.52php.cn/article/p-heplvrqh-bgy.html 本文出自:【江清清的博客】 (一)前言【好消息】个人网站已经上线运行,后面博客以及技术干货等精彩文章会同步更新,请大家关注收藏:http://www.lcode.org 今天我们一起来看一下WebView组件讲解以及使用实例 刚创建的React Native技术交流群(282693535),欢迎各位大牛,React Native技术爱好者加入交流!同时博客左侧欢迎微信扫描关注订阅号,移动技术干货,精彩文章技术推送! 该WebView组件进行创建渲染一个原生的WebView,进行加载一个网页。 (二)属性方法
(三)实战实例上面我已经对于WebView组件的基本介绍以及相关属性方法做了讲解,下面我们用几个实例来演示一下WebView组件的使用。 3.1.先演示一个WebView组件最基本的使用方法,直接加载一个网页,具体代码如下: 'use strict'; import React,{ AppRegistry,Component,StyleSheet,Text,View,WebView,} from'react-native'; var DEFAULT_URL = 'http://www.lcode.org'; var WebViewDemo =React.createClass({ render: function() { return ( <View style={{flex:1}}> <Textstyle={{height:40}}>简单的网页显示</Text> <WebViewstyle={styles.webview_style} url={DEFAULT_URL} startInLoadingState={true} domStorageEnabled={true} javaScriptEnabled={true} > </WebView> </View> ); },}); var styles =StyleSheet.create({ webview_style:{ backgroundColor:'#00ff00',} }); AppRegistry.registerComponent('WebViewDemo',() => WebViewDemo); 运行效果截图如下: 3.2.WebView加载本地的HTML静态字符串,具体代码如下: 'use strict'; import React,} from'react-native'; var DEFAULT_URL = 'http://www.lcode.org'; const HTML = ` <!DOCTYPEhtml>n <html> <head> <title>HTML字符串</title> <metahttp-equiv="content-type" content="text/html;charset=utf-8"> <meta name="viewport"content="width=320,user-scalable=no"> <style type="text/css"> body { margin: 0; padding: 0; font: 62.5% arial,sans-serif; background: #ccc; } h1 { padding: 45px; margin: 0; text-align: center; color: #33f; } </style> </head> <body> <h1>加载静态的HTML文本信息</h1> </body> </html> `; var WebViewDemo =React.createClass({ render: function() { return ( <View style={{flex:1}}> <WebViewstyle={styles.webview_style} html={HTML} startInLoadingState={true} domStorageEnabled={true} javaScriptEnabled={true} > </WebView> </View> ); },() => WebViewDemo); 运行效果截图如下: (四)最后总结今天我们主要学习一下WebView组件的基本介绍和实例演示使用,具体还有更加详细的使用方法会在后面进阶中继续更新的。大家有问题可以加一下群React Native技术交流群(282693535)或者底下进行回复一下。 尊重原创,转载请注明:From Sky丶清(http://blog.csdn.net/developer_jiangqq) 侵权必究! 关注我的订阅号(codedev123),每天分享移动开发技术(Android/IOS),项目管理以及博客文章!(欢迎关注,第一时间推送精彩文章)
关注我的微博,可以获得更多精彩内容
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |