這只是一個「佈局」,這意味着你還需要自己提供一個viewController和一個collectionView,然後把這三件事情包起來!
下面是一個例子: 在你WaterfallViewController.h
#import "UICollectionViewWaterfallLayout.h"
@interface WaterfallViewController : UIViewController <UICollectionViewDataSource, UICollectionViewDelegate, UICollecitonViewDelegateWaterfallLayout>
@property (nonatomic, strong) UICollectionView *collectionView;
@end
而在你WaterfallViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
UICollectionViewWaterfallLayout *layout = [[UICollectionViewWaterfallLayout alloc] init];
layout.delegate = self;
layout.columnCount = 2;
layout.itemWidth = 146;
layout.sectionInset = UIEdgeInsetsMake(9, 9, 9, 9);
_collectionView = [[UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:layout];
_collectionView.dataSource = self;
_collectionView.delegate = self;
_collectionView.showsVerticalScrollIndicator = NO;
_collectionView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
[_collectionView registerClass:[MyCell class] forCellWithReuseIdentifier:@"MyCell"];
[self.view addSubview:self.collectionView];
}
#pragma mark - UICollecitonViewDelegateWaterfallLayout Delegate
- (CGFloat)collectionView:(UICollectionView *)collectionView
layout:(UICollectionViewWaterfallLayout *)collectionViewLayout
heightForItemAtIndexPath:(NSIndexPath *)indexPath
{
// return the height for cell at indexPath.
}
很抱歉給您帶來不便,我會添加一些示例代碼回購不久。
Nelson-有沒有辦法給你的控件添加標題? –