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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:41:52+00:00 2026-05-25T15:41:52+00:00

I have a UIButton that has a UIImageView inside of it. For some reason

  • 0

I have a UIButton that has a UIImageView inside of it. For some reason the button is being displayed to the left of the images. Here is my code:

// Load resources
for (int x = 0; x < [self.gameOptions.categories count]; x++)
{
    Category* category = [self.gameOptions.categories objectAtIndex:x];
    UIButton* imageButton = [UIButton buttonWithType:UIButtonTypeCustom];
    NSMutableArray* imageArray = [NSMutableArray new];
    UIImageView* imageView = [[UIImageView alloc] init];

    for (int i = 0; i < [category.resources count]; i++)
    {
        Resource* resource = [category.resources objectAtIndex:i];

        [imageArray addObject:resource.targetImage];
    }

    imageView.animationDuration = [imageArray count] * 2;
    imageView.animationImages = imageArray;
    int count = [self.categoryButtons count];
    imageView.frame = CGRectMake((count) * 50 + (count) * 10, 0, 50, 50);
    [imageView startAnimating];

    imageButton.adjustsImageWhenHighlighted = NO;
    imageButton.tag = category.categoryId;
    [imageButton addTarget:self action:@selector(imageSelect:) forControlEvents:UIControlEventTouchUpInside];
    imageButton.frame = CGRectMake(imageView.frame.origin.x, imageView.frame.origin.y, imageView.frame.size.width, imageView.frame.size.height); 
    DLog(NSStringFromCGPoint(imageButton.layer.frame.origin));
    DLog(NSStringFromCGPoint(imageView.frame.origin));
    DLog(NSStringFromCGPoint(imageButton.frame.origin));
    DLog(NSStringFromCGPoint(imageView.layer.frame.origin));
    [imageButton addSubview:imageView];


    [categorySelection setContentSize:CGSizeMake(imageView.frame.size.width, imageView.frame.size.height)];
    [categorySelection addSubview:imageButton];
    [self.categoryButtons addObject:imageButton];
    [imageArray release];
    [imageView release];
} 
  • 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-25T15:41:53+00:00Added an answer on May 25, 2026 at 3:41 pm

    Each view has its own origin for its subviews.

    so setting the ImageView.frame.origin of the same as the ButtonView.frame.origin isn’t going to put them in the exact same place in respect to the superview.

    so your imageView needs the origin set to values relative to the top left corner of your button.

    imageButton.frame = CGRect(20.0, 20.0, 100.0, 100.0);
    //then say you want the image to in the top left corner of the button
    imageView.frame = CGRect(0.0, 0.0, 50.0, 50.0);
    [imageButton addSubview:imageView];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a UIButton that is created inside of each table cell. I want
I have a table containing images and buttons. Each button has a tag with
I have a UIButton that is added to a UIImageView (it's a big chart)
I have a custom UIButton that has the label Name. When the user clicks
I have an iphone app that has a root view with a button that
I have a very simply subclass of UIButton that will fire off a custom
I have an app that uses a tableview, along with a UIButton that I
I have a method that accepts a sender and is called with a UIbutton.
I have a NIB with a UIView that contains some UILabels, UIButtons etc. and
I have a UIButton that I disable for a few seconds after the user

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.