上次咱们建立了一个简单的Weex的demo。git
WXSDKEngine:SDK开放的绝大多数接口都在此有声明。 WXLog: 用来打印日志。 WXDebugTool: weex提供的对外调试工具。 WXAppConfiguration: 使用weex开发的业务性配置。
一、浏览器查看
建议你们能够看下阿里团队的weex文章。
在上篇的helloweex.we 中的div标签中 加入图片image标签和thumbnail样式,所有代码:github
<template> <div> <image class="thumbnail" src="https://img.alicdn.com/tps/TB15vyaLpXXXXXXXFXXXXXXXXXX-198-46.png"></image> <text class="title" onclick="onClickTitle">Hello Weex</text> </div> </template> <style> .title { color: red; } .thumbnail { width: 100; height: 30; } </style> <script> module.exports = { methods: { onClickTitle: function (e) { console.log(e); alert('title clicked.'); } } } </script>
运行weex helloWeex.we 后,效果以下:浏览器
二、iOS端显示图片
咱们执行 weex helloWeex.we -o helloWeex.js 。而后把生成的helloWeex.js 替换到项目中。
而后在iPhone上运行 会发现 图片并无显示出来。
首先咱们新建一个 WXImageDownloader 类,用来实现图片下载协议WXImgLoaderProtocol。weex
代码以下:工具
#import <WeexSDK/WeexSDK.h> @interface WXImageDownloader : NSObject <WXImgLoaderProtocol> @end
在.m文件中实现WXImgLoaderProtocol协议的downloadImageWithURL方法。用SDWebImage下载图片。url
#import "WXImageDownloader.h" #import <SDWebImage/SDWebImageManager.h> @implementation WXImageDownloader - (id<WXImageOperationProtocol>)downloadImageWithURL:(NSString *)url imageFrame:(CGRect)imageFrame userInfo:(NSDictionary *)options completed:(void(^)(UIImage *image, NSError *error, BOOL finished))completedBlock { return (id<WXImageOperationProtocol>) [[SDWebImageManager sharedManager] downloadImageWithURL:[NSURL URLWithString:url] options:0 progress:^(NSInteger receivedSize, NSInteger expectedSize) { } completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { if (completedBlock) { completedBlock(image, error, finished); } }]; } @end
而后在AppDelegate中注册Handler:调试
[WXSDKEngine registerHandler:[WXImageDownloader new] withProtocol:@protocol(WXImgLoaderProtocol)];
运行后的效果为:
日志
源代码的地址仍是 上篇文章中的github地址。code