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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T20:40:37+00:00 2026-06-03T20:40:37+00:00

I have a UIScrollView and a UIPageControl on my View in my iPhone app.

  • 0

I have a UIScrollView and a UIPageControl on my View in my iPhone app. I populate this Scrollview with a list of 10 buttons. The buttons all populate correctly an I can scroll through them perfectly. My question is: How do I wire up a click event to each of those buttons? Each button will perform essentially the same task (Play a sound) however the sound will be different for each of these buttons. The buttons are created programatically by the following method:

    private void CreatePanels()
    {
        scrollView.Scrolled += ScrollViewScrolled;

        int count = 10;
        RectangleF scrollFrame = scrollView.Frame;
        scrollFrame.Width = scrollFrame.Width * count;
        scrollView.ContentSize = scrollFrame.Size;

        for (int i=0; i<count; i++)
        {
            
            float h = 150.0f;
            //float w = 50.0f;
            float padding = 10.0f;
            int n = 25;
            
            var button = UIButton.FromType (UIButtonType.RoundedRect);
            button.SetTitle (i.ToString (), UIControlState.Normal);
            UIImage img = new UIImage("Images/btntest.png");
            button.SetImage(img, UIControlState.Normal);
            button.Frame = new RectangleF (
                        (padding + 40) * (i + 1) + (i * (View.Frame.Width - 100))   , 
                        padding,                        
                        View.Frame.Width - 100,         
                        h);

            RectangleF frame = scrollView.Frame;
            PointF location = new PointF();
            location.X = frame.Width * i;

            frame.Location = location;
            button.Frame = frame;

            scrollView.AddSubview(button);
        }

        pageControl.Pages = count;
    }
    
    private void ScrollViewScrolled (object sender, EventArgs e)
    {
        double page = Math.Floor(((scrollView.ContentOffset.X - scrollView.Frame.Width) / 2) / scrollView.Frame.Width) + 1;

        pageControl.CurrentPage = (int)page;
    }

The CreatePanels() method is called within the ViewDidLoad() method which populates the UIScrollView.

How can I link a click event to each of these buttons? I have searched the internet a lot but to no avail.

  • 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-03T20:40:45+00:00Added an answer on June 3, 2026 at 8:40 pm

    What about wiring up an anonymous method to each click event in the for loop?

    button.TouchUpInside += (s, e) =>
    {
    //play i.mp3
    };

    I’m not sure how to actually play a sound file but you could have your sound files named as i.* since that is what your buttons are named.

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

Sidebar

Related Questions

I have UIScrollView in my view. Problem is that if I slightly scroll it
I have a UIScrollView with 2 pages, and I can scroll horizontally between them.
I have a UIScrollView that houses a gallery of images the user can scroll
I have a UIScrollView . The scrollview.contentSize is set to the height of all
I have a UIScrollView which contains a view (lets call this main view) which
I have this UIScrollView inside another UIView, not occuping the entire area (all this
I have a UIScrollView on screen. Scroll view contains a view in which are
I have main UIScrollView with lots off buttons which i create like this: UIButton
I have a UIScrollView that contains multiple UITableViews horizontally - all of which are
I have a UIScrollView in my project. I have a view controller I would

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.