Skip to content

Instantly share code, notes, and snippets.

@johncalvinyoung
Created July 26, 2012 02:03
Show Gist options
  • Save johncalvinyoung/3179831 to your computer and use it in GitHub Desktop.
Save johncalvinyoung/3179831 to your computer and use it in GitHub Desktop.
Auto-positioning hand draw code
CGFloat xOffset = 240 - (((player.hand.count*20)+52)/2);
__block CGPoint location = CGPointMake ((CGFloat) xOffset, (CGFloat) 0);
[player.hand enumerateObjectsUsingBlock:^(RMSPlayingCard *obj, NSUInteger idx, BOOL *stop) {
NSString *rank = obj.rank;
NSString *suit = obj.suit;
UIImage *cardImage = [UIImage imageNamed:[NSString stringWithFormat:@"%@%@.png", [[suit substringToIndex:1] lowercaseString], [[rank substringToIndex:1] lowercaseString]]];
UIImageView *cardView = [[UIImageView alloc] initWithFrame:CGRectMake(location.x, location.y, cardImage.size.width, cardImage.size.height)];
[cardView setImage:cardImage];
[self.handView addSubview: cardView];
location.x = location.x+20;
}];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment