要运行示例项目,克隆存储库,并首先从示例目录运行pod install
。
WLCardViewLayout通过CocoaPods提供。要安装它,只需将以下行添加到Podfile
pod "WLCardViewLayout"
然后将cardlayout关联至Controller
@property (weak, nonatomic) IBOutlet WLCardViewLayout *cardLayout;
- (void)viewDidLoad {
[super viewDidLoad];
[self.cardLayout setSwipeToDeleteDelegate:self];
}
//CollectView数据源代理
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return 1;
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
return list.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CardCell" forIndexPath:indexPath];
UIImageView *im = [cell viewWithTag:100];
[im setImage:[UIImage imageNamed:list[indexPath.section]]];
return cell;
}
//swipe删除数据源代理
-(void)swipeToDeleteLayout:(WLCardViewLayout *)layout didDeleteCellAtIndexPath:(NSIndexPath *)indexPath{
[list removeObjectAtIndex:indexPath.section];
}
WLCardViewLayout可根据MIT许可使用。有关更多信息,请参阅LICENSE文件。