基于LazyScroll,我们创造了一个动态创建视图UI页面的解决方案,详情可见 Tangram-iOS
。
LazyScrollView 是 iOS 的 ScrollView,用于解决视图的复用问题。
与 UITableView 相比,LazyScrollView 可以轻松创建不同的布局,而不是单行流布局。
与 UICollectionView 相比,LazyScrollView 可以在没有 Grid 布局的情况下创建视图,并且提供了一种在 ScrollView 中创建不同类型布局的更简单的方法。
我们创建了一个模块化的 UI 解决方案,用于基于 动态构建 UI 页面 LazyScrollView
,您可以从这个 repo 中看到更多信息:
安装
LazyScroll
LazyScroll
在 CocoaPods 中可用。
pod 'LazyScroll'
您还可以从
发布页面下载源文件并手动将它们添加到您的项目中。
用法
#import "TMMuiLazyScrollView.h"
然后,创建 LazyScrollView:
TMMuiLazyScrollView *scrollview = [[TMMuiLazyScrollView alloc ]init];
scrollview.frame = self.view.bounds;
接下来,实现
TMMuiLazyScrollViewDataSource
:
@protocol TMMuiLazyScrollViewDataSource <NSObject>
@required
// Number of items in scrollView.
- (NSUInteger)numberOfItemInScrollView:(TMMuiLazyScrollView *)scrollView;
// Return the view model (TMMuiRectModel) by index.
- (TMMuiRectModel *)scrollView:(TMMuiLazyScrollView *)scrollView rectModelAtIndex:(NSUInteger)index;
// Return view by the unique string that identify a model (muiID).
// You should render the item view here.
// You should ALWAYS try to reuse views by setting each view's reuseIdentifier.
- (UIView *)scrollView:(TMMuiLazyScrollView *)scrollView itemByMuiID:(NSString *)muiID;
@end
接下来,设置 LazyScrollView 的数据源:
scrollview.dataSource = self;
最后,重新加载:
[scrollview reloadData];
有关更多详细信息,请克隆 repo 并打开演示项目。