Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8248403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:10:45+00:00 2026-06-07T23:10:45+00:00

I am trying to make a game where if you tap something a small

  • 0

I am trying to make a game where if you tap something a small 50X53 image displays right where you tapped it, i started by making the 50×53 image thing a button, that when you touch the button the background of the button changes to red (to simulate that an image was just added there) so here i have about 48 buttons (6X8) on my viewController and whenever i press one of those button the background changes to red, ok simple enough, but now what i want to do is have the UI be completely blank (you can’t see any buttons) and then when you press a given area an image pops up in that small space you pressed. I figured instead of doing

-(IBAction)imagePressed
{
sender.background=[UIColor redColor];
}


-(IBAction)imagePressedAgain
{
sender.background=[UIColor whiteColor];
}

i was going to do something like

-(IBAction)imagePressed
{
sender.image=@"whateverImage.png";
//I know this isn't the right syntax to change a buttons image (and i don't even know if i can change a buttons image) but anyways i was going to try to here
}
-(IBAction)imagePressedAgain
{
sender.image=@"imageThatIsJustAWhiteBackground";
}

so i tried doing this and then thought to myself, hmmm maybe I’m not supposed to do it this way, am i supposed to use a bunch of tiny UIImageViews and put them all on the interfaceBuilder? Like instead of having 48 buttons across the screen i would have 48 UIImageViews? and then I guess i would add a tap gesture recognizer to each? Or should i just stick to my old plan and change the buttons image?

(o, and btw i can’t have the images show exactly in proportion to where the user touched his finger on the screen, i have to have it in an organized grid so i have to have like 48 of them.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T23:10:48+00:00Added an answer on June 7, 2026 at 11:10 pm

    If you want to maintain the gird-like arrangement as you described (6×8), you can do something like the following:

     NSMutableArray *buttons = [[NSMutableArray alloc] init];
    
    // Loop through and create 48 buttons at 50 x 53
    for(int i = 0; i < 48; i++)
    {
        UIButton *pressMe = [UIButton buttonWithType:UIButtonTypeCustom];
    
        [buttons addObject:pressMe];
        pressMe.frame = CGRectMake(0, 0, 50, 53);
        // Set background image for when button is selected
        [pressMe setBackgroundImage:[UIImage imageNamed:@"selectedImage.png"] forState:UIControlStateSelected];
        // Add target to toggle selected state of button
        [pressMe addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
    }
    
    int col = 0;
    int row = 0;
    int maxPerRow = 6;
    float spacingHorizontal = 50;
    float spacingVertical = 53;
    
    for(UIButton *view in buttons)
    {
        // position buttons in 6 x 8 grid
        view.frame = CGRectMake(col * spacingHorizontal, row * spacingVertical, view.frame.size.width, view.frame.size.height);
        [self.view addSubview:view];
    
        if(col % maxPerRow == maxPerRow-1)
        {
            col = 0;
            row++;
        }
        else
        {
            col++;
        }
    }
    

    You can see the important part is setting the selected image for the button. This will allow you to show your custom image when the button is tapped. Here’s a screen cap of my test. If you want i can give you the project files.

    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to make an xna game, where the user needs to tap to stop
I am just messing around trying to make a game right now, but I
I'm trying to make a game with Qt, but i can't load an image.
I'm trying to make a small game that supports Python scripting. I've no problems
I am trying to make a small game like app that has some interaction,
I'm trying to make a small game using both SFML and Box2D. I have
I'm trying to make a small game using (free)GLUT. I know that it's old
I`m trying to make a small game on node.js + socket.io + mysql. The
I am trying to make a game in which a button is clicked, and
I am trying to make the game Asteroids. My issue I have right now,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.