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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:29:49+00:00 2026-05-17T23:29:49+00:00

I am trying to create a scrollable menu bar (which I am succeeding in

  • 0

I am trying to create a scrollable menu bar (which I am succeeding in doing) but now instead I want to add a large button with an image centred in the button, instead of taking up the total width and height of the button

THis is my current code:

[scrollView setBackgroundColor:[UIColor whiteColor]];

[scrollView setCanCancelContentTouches:NO];

scrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;

scrollView.clipsToBounds = YES;

scrollView.scrollEnabled = YES;

UIImage *image;

UIImageView *iv;

UIButton *button;

count = [returned count];

for (int i=0; i<count; i++)

{

image = [UIImage imageNamed:@"coat2.jpg"];

iv = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,105,120)];

button = [[UIButton alloc] initWithFrame:CGRectMake(0,0,105,120)];

[button setAlpha:100];

[button setTag:1];

[button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];

iv.image = image;

iv.tag=@"coat2.jpg";

iv.userInteractionEnabled = YES;

[iv insertSubview:button atIndex:0];

[button release];

[scrollView addSubview:iv];

[iv release];

}

[scrollView setScrollEnabled:YES];

[self layoutScrollImages];

scrollView.delegate = self;

the above code creates an image and button over it where the button and image are of the exact same width and height. I want the button to be significantly larger both in height and width.

Is this possible?

Thanks!

2nd attempt (using help from Joseph Tura)

[scrollView setBackgroundColor:[UIColor whiteColor]];

    [scrollView setCanCancelContentTouches:NO];

    scrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;

    scrollView.clipsToBounds = YES;

    scrollView.scrollEnabled = YES;

    UIImage *image;

    count = [returned count];

    for (int i=0; i<count; i++)

    {
    image = [UIImage imageNamed:@"coat2.jpg"];
                iv = [[UIImageView alloc] initWithFrame:CGRectMake(0,20,105,120)];

        button = [[ProductButton alloc] initWithFrame:CGRectMake(0,20,105,120)];

        [button setAlpha:100];
        [button setTag:1];
        [button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];

        iv.tag=tag;
        iv.userInteractionEnabled = YES;
        iv.image = myimage;

        UIView *uiView = [[UIView alloc] initWithFrame:CGRectMake(0,20,105,120)];
        [uiView addSubview:iv];
        button = [[ProductButton alloc] initWithFrame:CGRectMake(0,0,210,240)];
        button.center = CGPointMake(uiView.frame.size.width /2, uiView.frame.size.height/2);
        [button setTag:1];

        [button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
        [uiView addSubview:button];

        [scrollView addSubview:uiView];
}
                [scrollView setScrollEnabled:YES];

    [self layoutScrollImages];

    scrollView.delegate = self;


-----

-(void)layoutScrollImages
{
    //UIImageView *view = nil;
    UIView *view = nil;
    NSArray *subviews = [scrollView subviews];
    CGFloat curXLoc = 0;
    for (view in subviews)
    {
        if ([view isKindOfClass:[UIView class]] && view.tag > 0)
        {
            CGRect frame = view.frame;
            frame.origin = CGPointMake(curXLoc, 0);
            view.frame = frame;

            curXLoc += 110;
        }
    }
    [scrollView setContentSize: CGSizeMake(count*110, [scrollView bounds].size.height)];
}
  • 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-17T23:29:49+00:00Added an answer on May 17, 2026 at 11:29 pm

    Why not put both elements inside a UIView?

    UIView *aView = [[UIView alloc] initWithFrame:iv.frame];
    
    [aView addSubview:iv];
    
    button = [[UIButton alloc] initWithFrame:CGRectMake(0,0,210,240)];
    button.center = CGPointMake(aView.frame.size.width / 2, aView.frame.size.height / 2);
    [aView addSubview:button];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a scrollable menu list in JavaScript and I am
Trying to create a user account in a test. But getting a Object reference
I'm trying to create a sitemap using Linq to Xml, but am getting an
I'm trying to create a webapplication where I want to be able to plug-in
I am trying to create a scrollable panel within a table cell. What I
I'm trying to create a scrollable layout in Android. Even using developers.android.com, though, I
I am trying to create a scrollable DIV using the following: <!DOCTYPE html PUBLIC
I want to create a scrollable div tag with a fixed height that gets
Ok so I have a tab class that is scrollable which works fine, but
I am trying create a WCF service that leverages the WPF MediaPlayer on the

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.