i'm new in iPhone app development i'm developing a game in which involves choosing the right image from four choices. these choices are made up of custom buttons and i have 80 different images which should be loaded in each button per iteration. I've thought of making 80 different buttons for each image and hiding the 76 buttons while showing only 4 but that would take up a lot of memory. I've also thought of making only four buttons and load the different images there but the only way i know to put an image in a button through code is
[button setImage:image1 forState:UIControlStateNormal];
but using this would also take me a lot of lines for each button.
is there a way for me to load different images in a single button without taking up too much lines in my code?
Yes you can do in a very simple way. Create an array containing the the name of all 80 images. Use
[button setImage:[array objectAtIndex:k] forState:UIControlStateNormal];
k=k+1;
use above code four times as you have four buttons, increament k by each time. start k =0; so in first iteration you k=0, k=1, k=2, k=3 four values and this will continue in second iteration.
Related
In my carousel view after 7 images next image shows the first image , the other one shows the second image although they are different images. I mean after 7 images they start repeat images. I am sure it is coming different images. My images are buttons. When i click them they show detail view. In detail view they show correct images but in carousel not. Do you have any idea what causes that. Thank you.
It sounds like you are using the reusingView feature wrongly.
You can fix it by increasing numberOfVisibleItems, but that's not actually the right way to do it since it uses up more memory and slows down the carousel.
Paste your carousel:viewForItemAtIndex:reusingView: method into the question and I'll check it for you.
I need to grab the image for the UITableViewCellEditingStyleInsert button (green +). Of course, I would like to get it in the regular size and in 2x. I didn't think this would be so difficult, but I am having a hard time finding it. Is there a way to get this without a major hack?
There are some sites that provide free downloadable vectors of the iPhone User Interface elements. You should be able to get the green button from these packages. Since they are vectors, you can resize them to any size you'd like without losing detail.
Here's one site that links to multiple sites offering these downloads:
iPhone UI Elements
If none of these work for you, try searching online for something like 'iPhone vector UI elements.'
I have a series of UIButtons from 0 to N with a background image which is a color. I want to take a sequence of numbers from 0 to N, run through it and flash the corresponding button for each number sequentially. I have thought of changing the background to white and using sleep, but I haven't been able to get it to work. The buttons must flash sequentially with equal time spacing between the flashes. Pseudocode is:
for(i in sequence){
[[buttons objectAtIndex:i] flash];
//The flash must complete before the next button flashes.
}
Is there anyway to simulate the same animation as a button press, because that would be perfect? Basically I'm doing these flashes to show the user the sequence in which to press the buttons, is there a more elegante way to do this? Should I use some custom view instead of UIButton (I need it to be clickable, but I could program that instead of using a button)?
NSTimer is your friend. Check up on the documentation for it. You could have it fire at a set interval and just increment the count each time it fires.
For animation look at the animation methods provided for in UIView's documentation. Should have everything you need.
DO NOT USE sleep under any circumstances. This will make everything completely non responsive while its sleeping. There are all sorts of other more useful methods that allow for delays.
I have some .swf files I want to use in an iphone app for menu changes etc.
I have tried to loop through the images(200) to get the same effect, but it doesnt seem to be to my benefit.
What are the best ways to achieve this?
Edit
I currently use the following code
[A1 setImage:[UIImage imageNamed:#"m1.10001.png"] forState:UIControlStateNormal];
[A1 setImage:[UIImage imageNamed:#"m1.10002.png"] forState:UIControlStateNormal];
[A1 setImage:[UIImage imageNamed:#"m1.10003.png"] forState:UIControlStateNormal];
[A1 setImage:[UIImage imageNamed:#"m1.10004.png"] forState:UIControlStateNormal];
[A1 setImage:[UIImage imageNamed:#"m1.10005.png"] forState:UIControlStateNormal];
I wanted to add something like
[self performSelector:#selector(somecode to set image) withObject:A1 afterDelay:1.0];
This feels completely wrong, especially when I have around 200 images.
I need to types of animations.
Firstly I am trying to have a my menus which are png files covering the screen, which has buttons layered on top of that. I want the background to animate.
Secondly I have UIButtons which I need to change image as well, a series of about 5 images to disply, these 5 images are xported from a small swf file.
The buttons seem more difficult to do, but still I am not sure on achieving either of these.
Thanks
Looping does nothing in an event driven UI such as Cocoa Touch, you just block the main thread.
Try your animation using an NSTimer to call back into your animation step-and-display routine at your desired frame rate.
Why not animate the menu changes programatically? Are the .swf files that complicated that they can't be done in the iphone app?
Is there a was to covert the files to iPhone supported video files?
First of all, using UIAnimation with a plist of image names and some parser code is your best bet.
However, a new technology on the horizon may make your original idea possible. A new iPhone native Flash Animation parser called hiramkei is coming soon. You can add SWF file animations directly into Xcode projects.
Here's the link http://flash-on-iphone.com/demo/
thanks for all your advice I took out of this forum over the last weeks.
Now I've a problem where I would need your help:
I want to show a series of short animations (5 animations, 10 sec each) on the iPhone. The animation would loop but the code will decide if the current loop is repeated or another loop will be started (Laughing face, shouting face, crying face etc.).
I am a little concerned that if I would design this animation with single images to be played the size of the app would explode. So video came to my mind. On the other hand we need to overlay the animation with changing images, so video could be a kind of hassle.
Any ideas about the best way to go?
Thanx for all your advice.
Tom
For 5 animations of 10 seconds each, i would suggest using single images. And you can use UIImageView's inbuilt animation with repeat count. It will be very easy to code.
Only make sure not to use [UIImage imageNamed:#""] while creating image arrays as you might have many images. This method creates an autorelease object and you wouldn't want many such objects hanging around in your app.