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 9010151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:22:57+00:00 2026-06-16T02:22:57+00:00

I have a Round Rect Button that is correctly swapping out images. I want

  • 0

I have a Round Rect Button that is correctly swapping out images. I want to also change the text within them, but that text does not show up. Most questions on StackOverflow seem to deal with one but not the other, and the ones that seem most related end up being for a BarItem of some sort.

From within the IBAction for the button’s touch, I have the following.

 [sender setImage:[UIImage imageNamed:@"swappingCorrectly.png"] forState:UIControlStateNormal];
 [sender setTitle:(@"Aww, this doesn't show up!") forState:UIControlStateNormal];

As mentioned, the image is switched just fine — but that label isn’t showing up. I use the same text-swapping line in another button that isn’t swapping images and it works fine.

It just doesn’t show up after the first tap. Anyone know what I can do to make that text show up?

  • 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-16T02:22:59+00:00Added an answer on June 16, 2026 at 2:22 am

    This works for me.

    - (IBAction)buttonPressed:(id)sender {
        [sender setImage:[UIImage imageNamed:@"button.jpeg"] forState:UIControlStateNormal];
        [sender setTitle:(@"Aww") forState:UIControlStateNormal];
    }
    

    enter image description here

    enter image description here

    I did notice that the label is to the far right as opposed to dead center. Is it possible the label is rendering in the wrong spot? Commenting out the setTitle yields the same results with button title being offset by the image.

    How to turn a UIImageView into a button. Note: this is very dirty and should be wrapped into a class. I left in but commented out the code to just do something on tap. Whats not shown is the UIImageView that was thrown on a xib file and set to userenabled = true.

    #import "ViewController.h"
    
    @interface ViewController ()
    
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
        UITapGestureRecognizer* tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(buttonPressed:)];
        [[self fakeButton] addGestureRecognizer:tap];
    
        UILabel* label = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 250, 25)];
        label.text = @"unpressed";
        label.backgroundColor = [UIColor clearColor];
        [[self fakeButton] addSubview:label];
    }
    
    - (void)didReceiveMemoryWarning
    {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    
    - (void)buttonPressed:(id)sender {
    //    UIGestureRecognizer *gesture = (UIGestureRecognizer*)sender;
    //    UIImageView* temp = (UIImageView*)gesture.view;
    //    for (UILabel *label in temp.subviews) {
    //        label.text = @"pressed";
    //    }
    //    temp.image = [UIImage imageNamed:@"button.jpeg"];
    //    
    //    //if you want it to reset after a Delay
    //    [self performSelector:@selector(buttonUnpressed:) withObject:temp afterDelay:.2];
    
    }
    
    -(void)buttonUnpressed:(UIImageView*)view
    {
    
    //    for (UILabel *label in view.subviews) {
    //        label.text = @"unpressed";
    //    }
    //    view.image = [UIImage imageNamed:@"origButton.jpeg"];
    //    [self performSelector:@selector(buttonUnpressed:) withObject:view afterDelay:.2];
    }
    
    -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
    {
        UITouch *touch = [touches anyObject];
    
        CGPoint point = [touch locationInView:self.view];
    
        if (CGRectContainsPoint([[self fakeButton] frame], point))
        {
                //Do touch down state
            NSLog(@"touchStarted");
            [[self fakeButton] setImage:[UIImage imageNamed:@"button.jpeg"]];
            for (UILabel *label in [[self fakeButton] subviews]) {
                label.text = @"pressed";
            }
        }
    
    }
    -(void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
    {
        NSLog(@"touch ended");
        //remove touch down state
        [[self fakeButton] setImage:[UIImage imageNamed:@"origButton.jpeg"]];
        for (UILabel *label in [[self fakeButton] subviews]) {
            label.text = @"unpressed";
        }
    
    }
    
    @end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an jpg Image with a round object in a rect and want
I have a DATE column that I want to round to the next-lower 10
Hey! I have a xib file were i would like a round rect button
I have added some items, such as the pictured round rect button in Interface
I have a button that changes its image to different images depending on what
I got a simple question. I have a Round Rect button which contains an
I have a round image that I want to squish vertically so that it
For some reason I have a black underlay under my round rect buttons. This
I have two manifests that I swap round when building different releases of my
I have opened www.makemytrip.com website and try to click on Round Trip radio button

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.