基于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 并打開示範項目。