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

  • SEARCH
  • Home
  • 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 6086791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:47:45+00:00 2026-05-23T11:47:45+00:00

I have 3 different UIButtons for each image grouped. I have IDs for each

  • 0

I have 3 different UIButtons for each image grouped. I have IDs for each image. Right now, I have a special id for each image, and I set the button with that tag.

I want to change the background image of the one selected when you tap it. The problem is, is that 3 buttons have the same tag so I cannot change the right button’s background image.

Here’s what I have:

UIButton *likeButton = [UIButton buttonWithType:UIButtonTypeCustom];
[likeButton setBackgroundColor:[UIColor clearColor]];
[likeButton setBackgroundImage:[UIImage imageNamed:@"icon_like_button.png"] forState:UIControlStateNormal];
[likeButton setBackgroundImage:[UIImage imageNamed:@"icon_like_button_hit.png"] forState:UIControlStateSelected];
[likeButton setBackgroundImage:[UIImage imageNamed:@"icon_like_button_hit.png"] forState:UIControlStateHighlighted];
[likeButton setBackgroundImage:[UIImage imageNamed:@"icon_like_button_hit.png"] forState:UIControlStateDisabled];
[likeButton setFrame:CGRectMake(13, 52 + (285 * count), 51, 55)];
[likeButton addTarget:self action:@selector(likeDudle:) forControlEvents:UIControlEventTouchDown];
[likeButton setTag:theIdInt];
[likeButton setTitle:@"no_like" forState:UIControlStateNormal];
[scrollView addSubview:likeButton];

- (IBAction)likeDudle: (id)sender {

NSInteger tagId = ((UIControl*)sender).tag;

UIButton *tempButton = (UIButton*)[scrollView viewWithTag:tagId];

NSLog(@"likeDudle: %d // %@", tagId, tempButton.titleLabel.text);

if ([tempButton.titleLabel.text isEqualToString:@"no_like"]) {
    [tempButton setBackgroundImage:[UIImage imageNamed:@"icon_like_button_hit.png"] forState:UIControlStateNormal];
    [tempButton setTitle:@"like" forState:UIControlStateNormal];
} else if ([tempButton.titleLabel.text isEqualToString:@"like"]) {
    [tempButton setBackgroundImage:[UIImage imageNamed:@"icon_like_button.png"] forState:UIControlStateNormal];
    [tempButton setTitle:@"no_like" forState:UIControlStateNormal];
}

Is there a better way in doing this?

Thanks,
Coulton

  • 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-05-23T11:47:46+00:00Added an answer on May 23, 2026 at 11:47 am

    If you have fewer than 10 images, then give the ith button the tag i*10+image.tag. Then you can retrieve the image.tag by button.tag % 10 and the button tags will be unique. You can even retrieve the button only information by int b = button.tag/10.

    Also, you can access the button’s image’s tag with button.backgroundImage.tag, so then the button could have its own separate tagging system, depending on your uses.

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

Sidebar

Related Questions

Possible Duplicate: how to set image button backgroundimage for different state? I have the
I have an UIImageView on my view. Certain parts of that image, I want
I have a detail view that includes three UIButtons, each of which pushes a
I have a piano keyboard. Each button (key of the piano) has a different
I have 2 xib's. I want 2 different UIButtons to point to the same
I have a table containing images and buttons. Each button has a tag with
I currently have several action buttons in different pages, and each button performs some
I have different urls that points to the same code www.url1.com www.url2.com I need
I have noticed over the years that different developers have different criteria for what
I have two functions that have different enough logic but pretty much the same

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.