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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:35:39+00:00 2026-06-12T07:35:39+00:00

Want to show UIButton done on UIScrollView for images. With the below code UIButton

  • 0

Want to show UIButton done on UIScrollView for images. With the below code UIButton is showing but when I scroll UIImageViews, it shows only on very first imageview where as I want UIButton done should show on all image views in UIScrollView.

 - (void)viewDidLoad

 {
 self.view.backgroundColor = [UIColor blackColor];
UIScrollView *imageScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
UIButton *myButton = [UIButton buttonWithType:UIButtonTypeCustom];

[myButton addTarget:self action:@selector(dismissView:) forControlEvents:UIControlEventTouchUpInside];

myButton.frame = CGRectMake(0, 0, 60, 35);

[myButton.layer setMasksToBounds:YES];

[myButton.layer setCornerRadius:10.0f];

myButton.layer.borderWidth = 2;

myButton.layer.borderColor = [[UIColor whiteColor] CGColor];

[myButton setTitle:@"Done" forState:UIControlStateNormal];

myButton.backgroundColor = [UIColor blackColor];

UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithCustomView:myButton];

[[self navigationItem] setRightBarButtonItem:button animated:YES];
imageScrollView.pagingEnabled = YES;
NSInteger numberOfViews = 61;
for (int i = 0; i < numberOfViews; i++) {
    CGFloat xOrigin = i * self.view.frame.size.width;

    NSString *imageName = [NSString stringWithFormat:@"image%d.png", i];
    UIImage *image = [UIImage imageNamed:imageName];
    UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
    imageView.frame = CGRectMake(xOrigin, 0, self.view.frame.size.width, self.view.frame.size.height);
    [imageScrollView addSubview:imageView];
    [imageScrollView addSubview:myButton];
    [imageView release];
   }
imageScrollView.contentSize = CGSizeMake(self.view.frame.size.width * numberOfViews, self.view.frame.size.height);
[self.view addSubview:imageScrollView];
[imageScrollView release];
 }

How should I code it that UIButton Done should show on all image views when I scroll it.

  • 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-12T07:35:40+00:00Added an answer on June 12, 2026 at 7:35 am

    Add your UIButton in for loop i.e. it can add each time when your new ImageView is add.
    And change its x_Origin for each imageView –

    - (void)viewDidLoad
    {
        [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
        UIScrollView *imageScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    
        imageScrollView.pagingEnabled = YES;
        NSInteger numberOfViews = 61;
    
        for (int i = 0; i < numberOfViews; i++) 
        {
            CGFloat xOrigin = i * self.view.frame.size.width;
            UIButton *myButton = [UIButton buttonWithType:UIButtonTypeCustom];
            [myButton addTarget:self action:@selector(dismissView) forControlEvents:UIControlEventTouchUpInside];
            myButton.frame = CGRectMake(xOrigin, 0, 60, 35);
            [myButton setTitle:@"Done" forState:UIControlStateNormal];
            myButton.backgroundColor = [UIColor blackColor];
            [myButton.layer setMasksToBounds:YES];
    
           [myButton.layer setCornerRadius:10.0f];
            myButton.layer.borderWidth = 2;
            myButton.layer.borderColor = [[UIColor whiteColor] CGColor];
    
            NSString *imageName = [NSString stringWithFormat:@"image%d.png", i];
            UIImage *image = [UIImage imageNamed:imageName];
            UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
            imageView.frame = CGRectMake(xOrigin, 0, self.view.frame.size.width, self.view.frame.size.height);
            [imageScrollView addSubview:imageView];
            [imageScrollView addSubview:myButton];
        }
    
        imageScrollView.contentSize = CGSizeMake(self.view.frame.size.width * numberOfViews, self.view.frame.size.height);
        [self.view addSubview:imageScrollView];
    
    }
    

    Remove these 2 lines

    UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithCustomView:myButton];
    [[self navigationItem] setRightBarButtonItem:button animated:YES];
    

    There is no need to do this. This means you’re setting that button on rightBarButton of NavigationBar but in your case i think you dont want to do so.

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

Sidebar

Related Questions

I want to show my groupview with 2 lines to down direction, but only
i want show tooltip with image tag and i have written code like below
I have a UIButton with title in the middle. I want to show images
I want to show a border type look for an element but without using
I want show a form as a dialog but problem is that the worker
I have long page. I want show some info, so when user scroll page,
I have two overlay images that I want show in camera view depending on
I want to show the UIKeyboard upon tapping a UIButton and display the text
I am using this code for displaying Images in scroll view... In this buttons
As my Screen shot show that i have UIButton on SliderValueViewController.xib.i want that when

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.