Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/119.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ios使用仅图像代码实现PageController_C#_Ios_Xamarin.ios - Fatal编程技术网

C# ios使用仅图像代码实现PageController

C# ios使用仅图像代码实现PageController,c#,ios,xamarin.ios,C#,Ios,Xamarin.ios,我正在用xamarin开发一个ios应用程序,只有代码,没有故事板,也没有任何设计师。 我需要实现一个UiViewController,它包含许多图像,并水平滚动,就像 我没有找到适合我的东西。 有人给我一些建议或例子吗?似乎你需要一个不带故事板或.xib的UIPageViewController 您需要3个自定义类来实现它 MyPageViewController-自定义UIPageViewController public class MyPageViewController : UIPag

我正在用xamarin开发一个ios应用程序,只有代码,没有故事板,也没有任何设计师。 我需要实现一个UiViewController,它包含许多图像,并水平滚动,就像

我没有找到适合我的东西。
有人给我一些建议或例子吗?

似乎你需要一个不带故事板或.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;
    }