Last active
March 3, 2016 10:01
-
-
Save billyham/30f7ff22d09f1f747014 to your computer and use it in GitHub Desktop.
Game Piece UICollectionView
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <UIKit/UIKit.h> | |
#import "SPYArmyView.h" | |
@interface SPYBrigadeViewController : UICollectionViewController | |
@property (strong, nonatomic) NSNumber* numberOfArmies; | |
@property (strong, nonatomic) UIColor* brigadeColor; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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