Skip to content

Instantly share code, notes, and snippets.

@billyham
Last active March 3, 2016 10:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save billyham/30f7ff22d09f1f747014 to your computer and use it in GitHub Desktop.
Save billyham/30f7ff22d09f1f747014 to your computer and use it in GitHub Desktop.
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