LazyScrollView
基于 LazyScrollView,我们创造了一个动态创建模块化 UI 页面的解决方案,详情可见 Tangram-iOS。
LazyScrollView 是一个 iOS SofaView,旨在解决视图的重用问题。
与 UITableView 相比,LazyScrollView 可以轻松创建不同的布局,而不仅仅是一行的流程布局。
与 UICollectionView 相比,LazyScrollView 可以创建不需要网格布局的视图,并提供在 SofaView 中创建不同类型布局的更简单方式。
我们在《LazyScrollView》的基础上创建了一个模块化 UI 解决方案,动态构建 UI 页面,更多详情可在此仓库中查看:Tangram-iOS
安装
LazyScroll 在 Cocoapods 中可用作为 LazyScroll
。
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];
有关更多详细信息,请克隆仓库并打开演示项目。
微信群
搜索 tangram_
或扫描以上二维码添加 Tangram 为好友,以便我们邀请您加入群组。