Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Game Piece UICollectionView
#import <UIKit/UIKit.h>
#import "SPYArmyView.h"
@interface SPYBrigadeViewController : UICollectionViewController
@property (strong, nonatomic) NSNumber* numberOfArmies;
@property (strong, nonatomic) UIColor* brigadeColor;
@end
#import "SPYBrigadeViewLayout.h"
@interface SPYBrigadeViewController ()
@end
@implementation SPYBrigadeViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad{
[super viewDidLoad];
//register cell for collectionview
[[self collectionView] registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"Cell"];
[self.collectionView setClipsToBounds:NO];
}
#pragma mark - DataSource methods
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return [numberOfArmies integerValue];
}
-(UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"Cell";
UICollectionViewCell *cell = [self.collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
//initialize the army view
SPYArmyView* thisArmy = [[SPYArmyView alloc] initWithFrame:CGRectMake(0, 0, SPYArmyUnitWidth, SPYArmyUnitHeight)];
//assign the color to the armies property
thisArmy.baseColor = self.brigadeColor;
//make the background clear
[thisArmy setOpaque:NO];
thisArmy.backgroundColor = [UIColor clearColor];
[cell.contentView addSubview:thisArmy];
return cell;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.