我是ios开发的新手。我正试图在Xamarin ScrollView应用程序中创建一个垂直iOS。
下面是我的水平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.
}
}
}我想要创建一个垂直滚动视图并添加一些可滚动的文本视图。知道该怎么做吗?
如果您能详细说明如何让我的Main.storyboard文件中的元素按照如下所示的结构方案滚动,我将不胜感激:
-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还有更多。
发布于 2015-12-15 10:31:31
您需要设置ScrollView内容大小高度,比它的框架height.So要大--它将向上/向下滚动。滚动视图的宽度应该与其内容宽度相同,因此不会向右/向左滚动。
发布于 2017-11-07 11:06:44
我在找这个。我使用了许多有代码和没有代码的教程。进行滚动的最佳方法如下:
当您的屏幕变得更高,垂直约束将增加您的滚动视图。不需要代码,只需要适当的约束。
在您的示例中,您必须:
如果您的元素不适合xcode中的屏幕,请使用自由格式大小使控制器更大(这只适用于Xcode,而不适用于实际程序)
https://stackoverflow.com/questions/34285130
复制相似问题