|
| 1 | +[]() []() []() |
| 2 | + |
1 | 3 | # VirtualView |
2 | 4 |
|
3 | | -A solution to create custom view dynamically. |
| 5 | +A solution to create & release UI component dynamically. |
| 6 | + |
| 7 | +It a part of our [Tangram](https://github.com/alibaba/Tangram-iOS) solution. And it can be used as a standalone library. |
| 8 | + |
| 9 | +中文站点:[VirtualView](http://tangram.pingguohe.net/docs/virtualview/about-virtualview) |
| 10 | + |
| 11 | +## Features |
| 12 | + |
| 13 | + |
| 14 | + |
| 15 | +1. Write component via XML. |
| 16 | +2. Compile XML to a out (binary) file. |
| 17 | +3. Load out file in iOS application. |
| 18 | +4. Create component from loaded template and bind data to it. |
| 19 | +5. Show the component. |
| 20 | + |
| 21 | +## Install |
| 22 | + |
| 23 | +### CocoaPods |
| 24 | + |
| 25 | +Use VirtualView alone: |
| 26 | + |
| 27 | + pod 'VirtualView', '~> 1.0' |
| 28 | + |
| 29 | +Use VirtualView with [Tangram](https://github.com/alibaba/Tangram-iOS): |
| 30 | + |
| 31 | + pod 'Tangram', '~> 2.0' |
| 32 | + |
| 33 | +CocoaPods will install VirtualView as a part of Tangram 2.0. |
| 34 | +### Source codes |
| 35 | + |
| 36 | +Or you can download source codes from [release page](https://github.com/alibaba/VirtualView-iOS/releases) and put them into your project. |
| 37 | + |
| 38 | +## How to use |
| 39 | + |
| 40 | +1. Load component template from out file. |
| 41 | + |
| 42 | +```objective-c |
| 43 | +NSString *path = [[NSBundle mainBundle] pathForResource:@"icon" ofType:@"out"]; |
| 44 | +NSData *buffer = [NSData dataWithContentsOfFile:path]; |
| 45 | +[[VVBinaryLoader shareInstance] loadFromBuffer:buffer]; |
| 46 | +``` |
| 47 | +
|
| 48 | +2. Create component. |
| 49 | +
|
| 50 | +```objective-c |
| 51 | +self.container = (VVViewContainer *)[[VVViewFactory shareFactoryInstance] obtainVirtualWithKey:@"icon"]; |
| 52 | +[self.view addSubview:self.container]; |
| 53 | +``` |
| 54 | + |
| 55 | +3. Bind data and calc the layout. |
| 56 | + |
| 57 | +```objective-c |
| 58 | +self.container.frame = CGRectMake(0, 0, SCREEN_WIDTH, 1000); |
| 59 | +[self.container update:@{ |
| 60 | + @"type" : @"icon", |
| 61 | + @"imgUrl" : @"https://test.com/test.png" |
| 62 | +}]; |
| 63 | +``` |
| 64 | +
|
| 65 | +See more details in the demo project. |
| 66 | +
|
| 67 | +## Tools |
| 68 | +
|
| 69 | +See more details [here](https://github.com/alibaba/virtualview_tools). |
0 commit comments