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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T00:05:08+00:00 2026-06-05T00:05:08+00:00

I am trying to add uibutton inside the imageview. But it was not displayed

  • 0

I am trying to add uibutton inside the imageview.

But it was not displayed the button.

Even i tried adding it to the uiscrollview and also for self.view.

But nothing were displayed the uibutton

Pls let me know what is the problem

const CGFloat HEIGHT = 1024.0;
    const CGFloat WIDTH = 768.0;
    #define myViewPortrait CGRectMake(0.0f, 0.0f, 768.0f,1024.0f)
    #define myViewLandSacpe CGRectMake(0.0f, 0.0f, 1024.0f,768.0f)

    #define kAnimationKey @"animationKey"


    -(void)layoutScrollImages
    {
      UIImageView *view = nil;
      NSArray *subviews = [myScrollView subviews];

      CGFloat curXLoc = 0;
      for (view in subviews)
      {
        if ([view isKindOfClass:[UIImageView class]] && view.tag > 0)
        {
          CGRect frame = view.frame;
          frame.origin = CGPointMake(curXLoc, 0);
          view.frame = frame;

          curXLoc += (self.view.frame.size.width);
        }
      }

      [myScrollView setContentSize:CGSizeMake((myImagesCount * self.view.frame.size.width), [myScrollView bounds].size.height)];
    }   


    // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
    - (void)viewDidLoad {

      self.view.backgroundColor = [UIColor viewFlipsideBackgroundColor];
      myScrollView = [[UIScrollView alloc] initWithFrame:
      CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];

      [self.view addSubview:myScrollView];

      UISwipeGestureRecognizer *rightRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(rightSwipeHandle:)];
      rightRecognizer.direction = UISwipeGestureRecognizerDirectionRight;
      rightRecognizer.numberOfTouchesRequired = 1;
      [rightRecognizer setDelegate:self];
      [myScrollView addGestureRecognizer:rightRecognizer];
      [rightRecognizer release];

      UISwipeGestureRecognizer *leftRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(leftSwipeHandle:)];
      leftRecognizer.direction = UISwipeGestureRecognizerDirectionLeft;
      leftRecognizer.numberOfTouchesRequired = 1;
      [leftRecognizer setDelegate:self];
      [myScrollView addGestureRecognizer:leftRecognizer];
      [leftRecognizer release];

      [myScrollView setBackgroundColor:[UIColor blackColor]];
      [myScrollView setCanCancelContentTouches:NO];
      myScrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
      myScrollView.clipsToBounds = YES;     
      myScrollView.scrollEnabled = YES;
      myScrollView.pagingEnabled = YES;
      myScrollView.delegate = self;
      myImagesCount = 5;
      myScrollView.showsHorizontalScrollIndicator=NO;
      myScrollView.showsVerticalScrollIndicator=NO;

      for (int i = 1; i <= myImagesCount; i++)
      {
        NSString *imageName = [NSString stringWithFormat:@"screen-%d.jpg", i];
        UIImage *image = [UIImage imageNamed:imageName];
        UIImageView *imageView = [[UIImageView alloc] initWithImage:image];

        CGRect rect = imageView.frame;
        rect.size.height = myScrollView.frame.size.height;
          NSLog(@"%d -----",self.view.frame.size.width);
        rect.size.width = myScrollView.frame.size.width;
        imageView.frame = rect;
        imageView.tag = i;
        [myScrollView addSubview:imageView];
        [imageView release];
      }
    UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [button addTarget:self action:@selector(buttonHandler) forControlEvents:UIControlEventAllEvents];
    [button setTitle:@"point" forState:UIControlStateNormal];
    button.frame = CGRectMake(0.0, 0.0, 100.0, 40.0);
    button.backgroundColor = [UIColor blackColor];
    [self.view addSubview:button];
      [self layoutScrollImages];

      [super viewDidLoad];

    }
  • 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-05T00:05:10+00:00Added an answer on June 5, 2026 at 12:05 am

    Based off your question, you’d like to add the UIButton as a subview to the UIImageView – I’m guessing in the for loop? Immediate problem I see is that the actual button is being generated outside of the for loop. I think your for loop is intended to look like this:

    for (int i = 1; i <= myImagesCount; i++)
    {
        NSString *imageName = [NSString stringWithFormat:@"screen-%d.jpg", i];
        UIImage *image = [UIImage imageNamed:imageName];
        UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
    
        UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        [button addTarget:self action:@selector(buttonHandler)  forControlEvents:UIControlEventAllEvents];
        [button setTitle:@"point" forState:UIControlStateNormal];
        button.frame = CGRectMake(0.0, 0.0, 100.0, 40.0);
        button.backgroundColor = [UIColor blackColor];
    
        CGRect rect = imageView.frame;
        rect.size.height = myScrollView.frame.size.height;
        NSLog(@"%d -----",self.view.frame.size.width);
        rect.size.width = myScrollView.frame.size.width;
        imageView.frame = rect;
        imageView.tag = i;
    
        [imageView addSubview:button];
        [myScrollView addSubview:imageView];
        [imageView release];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to add a shadow to a UIButton layer, but for some reason
I'm trying to add a UIButton to a UIView, but am having some trouble
I am trying to add the UIButton to UIScrollView . I have added the
I am trying to add a UIButton at runtime however it is not visible.
I'm trying to add a UIButton to a UIView but I'm getting this error
. Hello, I am trying to add a UIButton and other items to my
Trying to add a class to a button if there has been any input
I'm trying to add a reload button to my navigation bar using this code
I'm having problems trying to add buttons into a UITableViewCell's content view. The button
I'm trying to add an Info button to the More screen that UITabBarController generates

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.