How to create a vertical scroll view in Xamarin iOS

I am new to ios development. I am trying to create a vertical ScrollView in a Xamarin iOS application.

Below is my code for horizontal scrollview

using System;

using UIKit;
using Foundation;
using CoreGraphics;
using System.Collections.Generic;

namespace TestApp
{
    public partial class ViewController : UIViewController
    {

    public ViewController (IntPtr handle) : base (handle)
    {
        ScrollingButtonsController ();
    }

    UIScrollView scrollView;
    List<UIButton> buttons;

    public override void ViewDidLoad ()
    {
        base.ViewDidLoad ();
        // Perform any additional setup after loading the view, typically from a nib.
        //MyScrollView.scrollEnabled=YES;
        //MyScrollView.contentSize= CGSizeMake(CGFloat.width, CGFloat.height);          

        //end
        nfloat h = 50.0f;
        nfloat w = 50.0f;
        nfloat padding = 10.0f;
        nint n = 100;

        scrollView = new UIScrollView {
            Frame = new CGRect (0, 100, View.Frame.Height, h + 2 * padding),
            ContentSize = new CGSize ((w + padding) * n, h),
            BackgroundColor = UIColor.Red,
            AutoresizingMask = UIViewAutoresizing.FlexibleWidth
        };

        for (int i=0; i<n; i++) {
            var button = UIButton.FromType (UIButtonType.RoundedRect);
            button.SetTitle (i.ToString (), UIControlState.Normal);
            button.Frame = new CGRect (padding * (i + 1) + (i * w), padding, w, h);
            scrollView.AddSubview (button);
            buttons.Add (button);
        }

        View.AddSubview (scrollView);

        //UIScrollView scrollView;
    //scrollView = new UIScrollView (
    //      new CGRect (0, 0, View.Frame.Width, View.Frame.Height));
    //  View.AddSubview (scrollView);



    }
    public void ScrollingButtonsController ()
    {
        buttons = new List<UIButton> ();

    }

    public override void DidReceiveMemoryWarning ()
    {
        base.DidReceiveMemoryWarning ();
        // Release any cached data, images, etc that aren't in use.
    }


}
}

I want to create a vertical scroll and add scrollable text views. Any idea on how to do this?

I would appreciate it if you could specify in detail how I can get the elements in the Main.storyboard file with the outline diagram, as shown below:

-Scroll View
--label
---Image View
---Text View
--label
---Image View
---Text View
--label
---Image View
---Text View
--label
---Image View
---Text View
--label
---Image View
---Text View

and much more...

+4
source share
2 answers

ScrollView, , . , /. , , /.

+3

. , . :

  • (, , , )

  • ,

  • , 2 :

    1) , ( )

    2) , ( )

, . , .

:

  • ,

  • ( )

Xcode, , ( xcode, ).

0

Source: https://habr.com/ru/post/1620076/


All Articles