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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:25:23+00:00 2026-05-26T12:25:23+00:00

I created a button programmatically: UIButton *myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; myButton.frame = CGRectMake(290, 120,

  • 0

I created a button programmatically:

UIButton *myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
myButton.frame = CGRectMake(290, 120, 40,20); // position in the parent view and set the size of the button
[myButton setTitle:@"Back" forState:UIControlStateNormal];
// add targets and actions
[myButton addTarget:self action:@selector(backLogin:) forControlEvents:UIControlEventTouchUpInside]; 
// add to a view
[myButton setAlpha:0];
[self.view addSubview:myButton];    

Now I would like to hide this button again using another method and use animation to make the button fade away (!).
Obviously, I cannot use the variable myButton again and I don’t want to make the variable global. Removing the Subview from the layer won’t animate I guess. Do you have an idea? I can’t make it to work… Thanks!

  • 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-26T12:25:23+00:00Added an answer on May 26, 2026 at 12:25 pm

    I don’t think you’re going about this the right way, but first of all, you’re adding an invisible button to your view. Assuming you meant to add the button with an alpha of 1, here we go.

    Fist of all, set a tag for the button:

    myButton.tag = 1;
    

    Any will do, as long as you’re not using that tag for something else.

    Next in your other method we can iterate through the subviews in your view controller and we can find the view with the tag of 1, and set it’s alpha to 0 with a nice fade effect:

    for (UIButton *button in self.view.subviews) {
        if (button.tag == 1) {
            [UIView animateWithDuration:2.0 animations:^ {
                button.alpha = 0;
            }];
        }
    }
    

    However, this is really a bad way to go about it, and I would highly suggest just creating an instance variable.

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

Sidebar

Related Questions

I create a button programmatically.......... button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; [button addTarget:self action:@selector(aMethod:) forControlEvents:UIControlEventTouchDown]; [button
I have created buttons are programmatically and set the button tags. View Did Load:
I have created 10 buttons programmatically and set the titles in the button. Now
I created a button programmatically to be added to the rightBarButtonItem. I had to
I have created a button programmatically and I want to fire event to go
I programmatically created a login view and a table view. Under certain circumstances which
I am creating a section view programmatically and I have a UIButton delete also
In Cocoa/Objective-C if I have created a button programmatically, what do I put in
I have created a grouped table view & I had a edit button in
Just created a new project in Xcode (View based), and tried creating a 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.