天貓開源了一個動態UI的方案,包含
https://github.com/alibaba/VirtualView-iOS
https://github.com/alibaba/tangram-ios
簡單來個Demo
1、常規創建工程,配置podfile
pod 'Tangram'
2、從github demo中copy CompileTool文件夾到工程目錄
VirtualView界面用xml配置,CompileTool會編譯成out二進制文件放到資源文件進行調用
3、加到工程的時候選中references。如果選groups,CompileTool中的文件會打包到ipa中
4、配置Build Phases。將CompileTool編譯的out文件拷貝到項目的Resources目錄
5、如果編譯報簽名問題
6、運行Demo
7、創建新的xml
8、在 templatelist.properties文件中增加配置,前面代表xml的名字,後面代表的編譯的out的文件名。
9、從out文件生成view
if (![[VVTemplateManager sharedManager].loadedTypes containsObject:@"Wuage"]) {
NSString *path = [[NSBundle mainBundle] pathForResource:@"Wuage" ofType:@"out"];
[[VVTemplateManager sharedManager] loadTemplateFile:path forType:nil];
}
self.container = [VVViewContainer viewContainerWithTemplateType:@"Wuage"];
self.container.delegate = self;
10、渲染效果
11、點擊事件
- (void)virtualViewClickedWithAction:(NSString *)action andValue:(NSString *)value
{
if (action) {
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"tap" message:action preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel handler:nil]];
[self presentViewController:alert animated:YES completion:nil];
}
}