Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mandude

macrumors member
Original poster
Nov 19, 2009
64
0
hey all I'm sure this is a very easy thing to do and it's done frequently but I'm wondering how to make a custom property for a UIImageView be set to a created identifier. This works great with a UIIamge, of course, however what if i want to assign the image view a custom property, suit for example. Im making a simple card game and I'd like to assign a card's ImageView a 'suit' property with an identifier, such as clubs, hearts, spades, or diamonds an example of what I'm looking for would be:

.h
Code:
UIImageView *card
UIImage *image;

@property (nonatomic, retain) UIImageView *card;

.m
Code:
card.image = image;
card.suit = clubs;
//or
card.suit = diamonds;

Then of course the identifiers need to be able to be compared between two card for the game I'm making, say if two cards are of the same suit, they interact and an event occurs because of it...

Code:
if (card1.suit == card2.suit) {
//magical things happen
}

is this sort of stuff possible? I'm sure it is, some guidance on what to put in the header file would be great thanks.
 

ViviUO

macrumors 6502
Jul 4, 2009
307
22
I believe you will have to make your own subclass of UIImageView to manipulate it the way you want to.
 

North Bronson

macrumors 6502
Oct 31, 2007
395
1
San José
You could try to put the different suits in an enumerated data type:

Code:
typedef enum
{
    NBSCardViewStyleNone,
    NBSCardViewStyleAce,
    NBSCardViewStyleClub,
    NBSCardViewStyleHeart,
    NBSCardViewStyleSpade
}
NBSCardViewStyle;

and then create your card views with something like:

Code:
- (id)initWithFrame:(CGRect)frame style:(NBSCardViewStyle)style
{
    self = [self initWithFrame: frame];
    
    if (self)
    {
        switch (style)
        {
            case NBSCardViewStyleAce:
            {
                break;
            }
            case NBSCardViewStyleClub:
            {
                break;
            }
            case NBSCardViewStyleHeart:
            {
                break;
            }
            case NBSCardViewStyleSpade:
            {
                break;
            }
            default:
            {
                break;
            }
        }
    }
    
    return self;
}

but you probably want to not keep too much data in your view classes. Is there a way to keep the data in your model classes and try to run the application from that?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.