C# ios使用仅图像代码实现PageController
我正在用xamarin开发一个ios应用程序,只有代码,没有故事板,也没有任何设计师。 我需要实现一个UiViewController,它包含许多图像,并水平滚动,就像 我没有找到适合我的东西。C# ios使用仅图像代码实现PageController,c#,ios,xamarin.ios,C#,Ios,Xamarin.ios,我正在用xamarin开发一个ios应用程序,只有代码,没有故事板,也没有任何设计师。 我需要实现一个UiViewController,它包含许多图像,并水平滚动,就像 我没有找到适合我的东西。 有人给我一些建议或例子吗?似乎你需要一个不带故事板或.xib的UIPageViewController 您需要3个自定义类来实现它 MyPageViewController-自定义UIPageViewController public class MyPageViewController : UIPag
有人给我一些建议或例子吗?似乎你需要一个不带故事板或.xib的
UIPageViewController
您需要3个自定义类来实现它
MyPageViewController
-自定义UIPageViewController
public class MyPageViewController : UIPageViewController
{
private List<ContentViewController> pages = new List<ContentViewController>();
public MyPageViewController() : base(UIPageViewControllerTransitionStyle.Scroll, UIPageViewControllerNavigationOrientation.Horizontal)
{
View.Frame = UIScreen.MainScreen.Bounds;
pages.Add(new ContentViewController(0,UIColor.Red));
pages.Add(new ContentViewController(1,UIColor.Green));
pages.Add(new ContentViewController(2,UIColor.Blue));
DataSource = new PageDataSource(pages);
SetViewControllers(new UIViewController[] { pages [0] as UIViewController }, UIPageViewControllerNavigationDirection.Forward, false, null);
}
}
ContentViewController
-自定义的UIViewController
,只需添加属性索引
public class ContentViewController : UIViewController
{
private int index = -1;
public int Index
{
get
{
return index;
}
}
public ContentViewController(int _index, UIColor backColor)
{
this.index = _index;
this.View.Frame = UIScreen.MainScreen.Bounds;
this.View.BackgroundColor = backColor;
}
}
AppDelegate.cs
中的FinishedLaunching
方法:
public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
{
this.Window = new UIWindow(UIScreen.MainScreen.Bounds);
this.Window.RootViewController = new MyPageViewController();
this.Window.MakeKeyAndVisible();
return true;
}
希望它能帮助你
如果您还有一些问题,请将其留在这里。该链接适用于tvOS,而不是iOS
public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
{
this.Window = new UIWindow(UIScreen.MainScreen.Bounds);
this.Window.RootViewController = new MyPageViewController();
this.Window.MakeKeyAndVisible();
return true;
}