-(CDHorizontalScrollView *)horizontalScrollView {
if (!_horizontalScrollView) {
_horizontalScrollView = [[CDHorizontalScrollView alloc] initWithFrame: CGRectMake(20, 200, self.view.frame.size.width, 120) withClassCell:[CDTestCollectionViewCell class] isNib: false withDelegate:self];
}
return _horizontalScrollView;
}
// cell个数 -(NSArray *)numberOfColumnsInCollectionView:(CDHorizontalScrollView *)collectionView {
return self.dataArray;
}
//每个item大小 -(CGSize)cellSizeForItemAtIndexPath:(NSIndexPath *)indexPath {
return CGSizeMake(120, 80);
}
//上左下右边距 -(UIEdgeInsets)collectionViewInsetForSectionAtIndex:(NSInteger)section {
return UIEdgeInsetsZero;
}
//每个item之间的间距 -(CGFloat)collectionViewMinimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
return 10;
}
// 选中cell -(void)didselectItemAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"选中%@", @(indexPath.row));
}
CDHorizontalScrollView is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'CDHorizontalScrollView'
CDHorizontalScrollView is available under the MIT license. See the LICENSE file for more info.