创建添加到UIViewController View 的 ScrollView
UIScroll scroll_View;
scroll_View = new UIScrollView {
BackgroundColor = UIColor.Black,
Frame = View.Frame,
ContentSize = new SizeF(320,720),
};
View.addSubView(scroll_View);// Added to Regisration ViewController
//创建文本字段
firstName = new UITextField {
Placeholder = "Enter firstName",
BorderStyle = UITextBorderStyle.None,
VerticalAlignment = UIControlContentVerticalAlignment.Center,
AutocorrectionType = UITextAutocorrectionType.No,
AutocapitalizationType = UITextAutocapitalizationType.None,
ClearButtonMode = UITextFieldViewMode.WhileEditing,
Background = TextFieldBackground,
LeftView = new UIView (new RectangleF (0, 0,8, 8)),
LeftViewMode = UITextFieldViewMode.Always,
ReturnKeyType = UIReturnKeyType.Next,
ShouldReturn = delegate {
lastName.BecomeFirstResponder ();
return true;
}
};
//像这样创建了 9 个文本字段和一个提交按钮。添加到 ScrollView
框架文本字段。
firstName.Frame = new RectangleF(80, 20, 200, 41);
lastName.Frame = new RectangleF(80, 70, 200, 41);
middle.Frame = new RectangleF(80, 120, 200, 41);
email.Frame = new RectangleF(80, 127, 200, 41);
password.Frame = new RectangleF(80, 220, 200, 41);
conformPassword.Frame = new RectangleF(80, 270, 200, 41);
phoneNumber.Frame = new RectangleF(80, 320, 200, 41);
description.Frame = new RectangleF(80, 370, 200, 41);
other.Frame = new RectangleF(80, 420, 200, 41);
buttonSubmit.Frame = new RectangleF(80, 470, 420, 41);
将文本字段添加到 ScrollView
scroll_View.addSubView(firstName);
scroll_View.addSubView(lastName);
scroll_View.addSubView(middleName);
scroll_View.addSubView(email);
scroll_View.addSubView(Password);
scroll_View.addSubView(conformaPassword);
scroll_View.addSubView(phoneNumber);
scroll_View.addSubView(description);
scroll_View.addSubView(other);
scroll_View.addSubView(buttonSubmit);
添加了 ScrollView UIViewController View 。
View.AddSubview (scroll_View);
当滚动滚动效果不起作用时。 Xamarin IOS。
Best Answer-推荐答案 strong>
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
float h = 50.0f;
float w = 50.0f;
float padding = 10.0f;
int n = 25;
_scrollView = new UIScrollView {
Frame = new RectangleF (0, 0, View.Frame.Width, h + 2 * padding),
ContentSize = new SizeF ((w + padding) * n, h),
BackgroundColor = UIColor.DarkGray,
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 RectangleF (padding * (i + 1) + (i * w), padding, w, h);
_scrollView.AddSubview (button);
_buttons.Add (button);
}
View.AddSubview (_scrollView);
}
关于c# - UIScrollView 滚动不工作 Xamarin IOS,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/24821658/
|