我是 ios 开发的新手。我正在尝试在 Xamarin iOS 应用程序中创建垂直 ScrollView 。
下面是我的水平 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.
}
}
}
我想创建一个垂直 ScrollView 并添加一些可滚动的 TextView 。关于如何做到这一点的任何想法?
如果您能详细说明如何使用如下结构方案滚动我的 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
还有更多...
最佳答案
您需要设置 ScrollView Content Size Height,大于它的框架高度。所以它会向上/向下滚动。 ScrollView 的宽度应与其内容宽度相同,因此它不会向右/向左滚动。
关于c# - 如何在 Xamarin iOS 中创建垂直 ScrollView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34285130/