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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:01:22+00:00 2026-05-25T02:01:22+00:00

how to set multiple buttons in UIScrollView and also how to set clicked action

  • 0

how to set multiple buttons in UIScrollView and also how to set clicked action for particular button index?

  • 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-25T02:01:22+00:00Added an answer on May 25, 2026 at 2:01 am

    you can call this(initScrollView) method on viewDidLoad

    - (void)viewDidLoad { 
    
    arrayScrollViewImages = [[NSArray alloc] initWithObjects:
         [[MyKeyValuePair alloc] initWithKey:@"imagename1" withValue:@"imagename1.png"],
         [[MyKeyValuePair alloc] initWithKey:@"imagename2" withValue:@"imagename2.png"],nil];
    
    
    [self initScrollView];
    
    }
    

    here arrayScrollViewImages is NSArray

    - (void) initScrollView
     {
    
        int width = 10;
        for (int index = 0; index < [arrayScrollViewImages count]; index++) {
            MyKeyValuePair *pair = [arrayScrollViewImages objectAtIndex:index];
            UIImage *image = [UIImage imageNamed:pair.value];
            UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
            [button setFrame:CGRectMake(width, 2, 34, 34)];
            [button setBackgroundImage:image forState:UIControlStateNormal];
            [button setTag:index];
            [button addTarget:self action:@selector(scrollViewButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
            if (index == 0) {
                [button setBackgroundColor:[UIColor colorWithRed:0.59 green:0.38 blue:0.21 alpha:1.00]];
            }
    
            [scrollView addSubview:button];
            width += 45;
        }
    
        scrollView.contentSize = CGSizeMake(width, 48);
        scrollView.contentOffset = CGPointMake(0, 0);
    }
    
    
    - (void) scrollViewButtonTapped:(id)sender {
        for (UIButton *b in scrollView.subviews) {
            if ([b isKindOfClass:[UIButton class]]) {
                [b setBackgroundColor:[UIColor clearColor]];
            }
        }
    
        UIButton *button = (UIButton *) sender;
        [button setBackgroundColor:[UIColor colorWithRed:0.59 green:0.38 blue:0.21 alpha:1.00]];
        MyKeyValuePair *pair = [arrayScrollViewImages objectAtIndex:button.tag];
        labelEspecialidad.text = pair.key;
    }
    

    here MyKeyValuePair is a one class
    *MyKeyValuePair.h*

    @interface MyKeyValuePair : NSObject {
        NSString *key;
        NSString *value;
    }
    
    // Properties
    @property (nonatomic, retain) NSString *key;
    @property (nonatomic, retain) NSString *value;
    
    @end
    

    MyKeyValuePair.m

    @implementation MyKeyValuePair
    @synthesize key, value;
    
    - (id) initWithKey: (NSString *) _key withValue: (NSString *) _value {
        if (self = [super init]) {
            self.key = _key;
            self.value = _value;
        }
    
        return self;
    }
    
    - (void) dealloc {
        [super dealloc];
        [self.key release];
        [self.value release];
    }
    
    @end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I set a primary key in multiple columns in Oracle, do I also
I have multiple table rows that has a set of radio buttons on each
I'm trying to dynamically set the Visible property of multiple boxes, panels, buttons etc.
Is there a way to set multiple alsoResizes in jQuery UI? $('.selector').resizable({ alsoResize: '.other'
Quote from Jason Coco it not possible to set multiple in UILabel... but how
I've set up multiple ssl sites on iis using Servier Bindings as per this
I have set up multiple targets in a single xml file. I expect all
I've set up multiple vhosts under apache2 / mod_perl. I used the ErrorLog directive
If I set up multiple event handlers, like so: _webservice.RetrieveDataCompleted += ProcessData1; _webservice.RetrieveDataCompleted +=
I am using urllib2 to interact with a website that sends back multiple Set-Cookie

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.