views:

74

answers:

2

I am confused about how to go adding objects (images,etc) into an app. I will keep my example very basic so I can get a grasp on this. Let's say I want simple objects in an app. Say they are the smilies like the ones that are available in this forum software. If you wanted to add a bunch (like 4 not 400) to a view, is it better to just add them with using a UIImage or should you create a "smilieGuy" class with the various smiley face images (happy, sad, mad) and a method to change their mood (image to reflect mood). From what I understand, with the class you could create a happy object, a sad object, etc in your view based off of the class and then at anytime you could say changeMood and change the image to whatever mood you wanted.

Is the class approach actually possible and is it a better approach?

+2  A: 

The class approach is preferable.

It allows you to separate the interface ([userFace setHappy]) from the implementation (self.image = [UIImage imageNamed:@"Happy.png"]). You can then change the logic, or create further variations without having to change any of the other display code.

Andrew Grant
A: 

I would also suggest creating an Emoticon class as a subclass of UIImageView. Inside the class, you could load your multiple images and use them to set the image property of your superclass.

You might also want to check out the animation properties of UIImageView to achieve Skype style smilies.

Roger Nolan