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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:55:29+00:00 2026-06-11T18:55:29+00:00

I have an imageView and within it I put a button. I have two

  • 0

I have an imageView and within it I put a button. I have two questions:

  • How can I properly add a button without losing its functionality?
  • How can I refer to my imageView within the method to animate the view?

The code:

- (void)viewDidLoad
{
    [super viewDidLoad];

    UIImageView *grayFrame = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"expSqrGray.png"]];

    [self.view addSubview:grayFrame];

    grayFrame.frame = CGRectOffset(grayFrame.frame, 0, 0);

    UIButton *testButton = [UIButton buttonWithType:UIButtonTypeCustom];
    testButton.frame = CGRectMake(20, 20, 200, 44);
    testButton.backgroundColor = [UIColor blackColor];
    [testButton setTitle:@"Test" forState:UIControlStateNormal];
    [testButton addTarget:self action:@selector(tapped:) forControlEvents:UIControlEventTouchUpInside];

    [grayFrame addSubview:testButton];
    //[self.view addSubview:testButton];
}
  • 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-11T18:55:30+00:00Added an answer on June 11, 2026 at 6:55 pm

    I have little to no knowledge about Objective-C but what you probably want to do is to make grayFrame and testButton member variables of your class. That way, your whole class has access to those two objects.

    For example:

    // Test.H
    @interface YourClass : NSObject {
       UIImageView * grayFrame;
       UIButton * testButton;
    }
    

    You can then have another method referring to either one of them.

    - (void) initializeObjects {
       grayFrame = [ [ UIImageView alloc ] initWithImage:[ UIImage imageNamed:@"expSqrGray.png" ] ];
       testButton = [ UIButton buttonWithType:UIButtonTypeCustom ];
    
       // Do things here.
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have imageView in activity. How I can set position this imageView in my
I have two ImageView s, iv1 and iv2 , where iv2 overlaps on the
I have a iPad app that can take a picture and then put it
I have an app where I have an imageview displayed within a UIView that
I have custom button, with an image that I'd like to shift down within
i can't seem to use UIViewContentModeScaleAspectFit property to scale my imageView within my scrollview
I have an imageview that moves up when i click a button. i want
So, in Interface Builder I have a view within the superview that contains two
I have an extended ImageView that I'm reusing 7 times horizontally (within a LinearLayout)
I have created a ShapeDrawable and placed it within an imageview that is dynamically

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.