103 lines
3.9 KiB
Objective-C
103 lines
3.9 KiB
Objective-C
//
|
|
// DSWebMenuCollectionView.m
|
|
// VietnamGame
|
|
//
|
|
//
|
|
|
|
#import "DSWebMenuCollectionView.h"
|
|
|
|
#import "DSAvatarCollectionViewCell.h"
|
|
|
|
static NSString *identifier = @"AvatarCollectionViewCell";
|
|
|
|
@implementation DSWebMenuCollectionView
|
|
|
|
-(void)awakeFromNib
|
|
{
|
|
[super awakeFromNib];
|
|
|
|
UICollectionViewFlowLayout *flowlayout = [[UICollectionViewFlowLayout alloc] init];
|
|
flowlayout.scrollDirection = UICollectionViewScrollDirectionVertical;
|
|
self.collectionViewLayout = flowlayout;
|
|
self.delegate = self;
|
|
self.dataSource = self;
|
|
self.showsVerticalScrollIndicator = NO;
|
|
self.showsHorizontalScrollIndicator = NO;
|
|
self.backgroundColor = [UIColor clearColor];
|
|
[self registerNib:[UINib nibWithNibName:@"DSAvatarCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:identifier];
|
|
[self registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:identifier];
|
|
}
|
|
|
|
-(void)setShareArray:(NSMutableArray<NSNumber *> *)shareArray
|
|
{
|
|
_shareArray = shareArray;
|
|
|
|
[self reloadData];
|
|
}
|
|
|
|
#pragma mark - 推荐
|
|
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
|
|
{
|
|
return 1;
|
|
}
|
|
|
|
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
|
|
{
|
|
return self.shareArray.count;
|
|
}
|
|
|
|
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
|
|
{
|
|
return CGSizeMake(collectionView.frame.size.width, ((collectionView.frame.size.height-(self.shareArray.count-1)*10))/self.shareArray.count);
|
|
}
|
|
|
|
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
|
|
{
|
|
return UIEdgeInsetsMake(0, 0, 0, 0);
|
|
}
|
|
|
|
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
|
|
{
|
|
return 10;
|
|
}
|
|
|
|
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
|
|
{
|
|
return 10;
|
|
}
|
|
|
|
-(UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
|
|
{
|
|
UICollectionReusableView *view = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:identifier forIndexPath:indexPath];
|
|
return view;
|
|
}
|
|
|
|
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
|
|
{
|
|
DSAvatarCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
|
|
NSNumber *number = self.shareArray[indexPath.row];
|
|
DSWebMenuType type = number.integerValue;
|
|
if (type == DSWebMenuHomeType) {
|
|
cell.avatarImageView.image = [UIImage imageNamed:@"zhongxindakai"];
|
|
}else if (type == DSWebMenuTelegramType) {
|
|
cell.avatarImageView.image = [UIImage imageNamed:@"telegram"];
|
|
}else if (type == DSWebMenuWhatsAppType) {
|
|
cell.avatarImageView.image = [UIImage imageNamed:@"whatsapp"];
|
|
}else if (type == DSWebMenuFacebookType) {
|
|
cell.avatarImageView.image = [UIImage imageNamed:@"facebook"];
|
|
}
|
|
cell.avatarImageView.contentMode = UIViewContentModeScaleAspectFit;
|
|
return cell;
|
|
}
|
|
|
|
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
|
|
{
|
|
NSNumber *number = self.shareArray[indexPath.row];
|
|
DSWebMenuType type = number.integerValue;
|
|
if (self.webMenuDelegate && [self.webMenuDelegate respondsToSelector:@selector(webMenuCollectionViewWithMenuType:)]) {
|
|
[self.webMenuDelegate webMenuCollectionViewWithMenuType:type];
|
|
}
|
|
}
|
|
|
|
@end
|