【发布时间】:2017-08-23 15:54:53
【问题描述】:
我试图让这个非常基本的 UIScrollView 水平滚动而不是垂直滚动。我在 Xamarin 开发人员网站上关注此示例:https://developer.xamarin.com/recipes/ios/content_controls/scroll_view/create_a_horizontal_scrolling_button_list/ 但我无法让按钮占据整个滚动视图而只能水平滚动。我一直在按钮列表的顶部和底部得到奇怪的填充。这是我的整个班级:
public partial class StackViewController : UIViewController
{
public StackViewController()
{
}
public override void DidReceiveMemoryWarning()
{
base.DidReceiveMemoryWarning();
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
this.View.BackgroundColor = UIColor.White;
nfloat h = 50.0f;
nfloat w = 50.0f;
nint n = 25;
UIScrollView scrollView = new UIScrollView
{
Frame = new CGRect(0, 100, View.Frame.Width, 100),
ContentSize = new CGSize((w) * n, h),
BackgroundColor = UIColor.Green
};
for (int i = 0; i < n; i++)
{
var button = new UIButton();
button.SetTitle(i.ToString(), UIControlState.Normal);
button.Frame = new CGRect((i * w), 0, w, h);
button.BackgroundColor = UIColor.Blue;
scrollView.AddSubview(button);
}
View.AddSubview(scrollView);
}
}
不知何故,我缺少一些我不知道的填充或布局属性。我是 Xamarin ios 开发的半新手,我知道我缺少一些简单的东西。
【问题讨论】:
标签: ios xamarin uiscrollview