Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Aug 11, 2011, 05:03 PM   #1
mandude
macrumors member
 
Join Date: Nov 2009
How to create a custom property and identifier?

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.
mandude is offline   0 Reply With Quote
Old Aug 11, 2011, 10:46 PM   #2
ViviUO
macrumors 6502
 
Join Date: Jul 2009
I believe you will have to make your own subclass of UIImageView to manipulate it the way you want to.
ViviUO is offline   0 Reply With Quote
Old Aug 12, 2011, 01:37 PM   #3
North Bronson
macrumors 6502
 
Join Date: Oct 2007
Location: Los Angeles
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?
__________________
North Bronson Software
North Bronson is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Tags
property identifier

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
iPhone: Create custom settings shortcut on iOs 5.1.1 zirosky Jailbreaks and iOS Hacks 3 Mar 25, 2013 12:56 PM
Looking to Create Custom Web Application VwTdi09 Web Design and Development 3 Oct 6, 2012 03:07 AM
How to create property thats also a custom made class? tradingjam Mac Programming 4 Aug 12, 2012 03:51 PM
How do I Create Custom Windows with Gradients? BigZ9 Mac Programming 1 Jul 17, 2012 10:39 PM

Forum Jump

All times are GMT -5. The time now is 06:03 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC