在UITabBarController中为每个选项卡添加webview?

时间:2017-05-04 11:39:20

标签: ios xamarin webview uiviewcontroller

如何在我的UIViewController中为每个选项卡添加Web视图?

public class TabController: UITabBarController
{
    UIViewController tab1, tab2, tab3, tab4, tab5, tab6, tab7;

    public TabController()
    {
        tab1 = new UIViewController();
        tab1.Title = "Test";
        tab1.View.BackgroundColor = UIColor.Orange;



        tab2 = new UIViewController();
        tab2.Title = "Test2";
        tab2.View.BackgroundColor = UIColor.Orange;

        tab3 = new UIViewController();
        tab3.Title = "Test3";
        tab3.View.BackgroundColor = UIColor.Red;

        tab4 = new UIViewController();
        tab4.Title = "Test4";
        tab4.View.BackgroundColor = UIColor.Red;

        tab5 = new UIViewController();
        tab5.Title = "Test5";
        tab5.View.BackgroundColor = UIColor.Red;

        tab6 = new UIViewController();
        tab6.Title = "Test6";
        tab6.View.BackgroundColor = UIColor.Red;

        tab7 = new UIViewController();
        tab7.Title = "Test7";
        tab7.View.BackgroundColor = UIColor.Red;




        var UIViewController = new UIViewController[] {
                            tab1, tab2, tab3, tab4, tab5, tab6, tab7
    };


        tab1.TabBarItem = new UITabBarItem(UITabBarSystemItem.Favorites, 0);

        ViewControllers = UIViewController;
    }
}

因此,对于每个标签,而不是" tab1.View.BackgroundColor = UIColor.Orange;",它 应该: Webview + Title + Link,以便每个标签都有不同的页面?

1 个答案:

答案 0 :(得分:1)

最简单的方法是使用故事板并将viewcontroller类分配给选项卡。但是,如果您想以编程方式执行此操作,我认为您需要执行以下操作:

    tab7 = new UIViewController();
    tab7.Title = "Test7";
    tab7.View.BackgroundColor = UIColor.Red;
    //Create a webview
    UIWebView webView = new UIWebView(View.Bounds); //Takes size as a constructor parameter
    //Set it's navigation location
    webView.Navigate(new URI("www.whatever.co.uk"));
    //Add the webview to the subviews of your UIViewController
    tab7.View.AddSubview(webView);

您可以为每个标签执行此操作。

另外值得一提的是,申请提交到他们商店的苹果指南确实倾向于对仅仅是网站表示的应用程序不满意,因此值得记住。该应用程序必须能够比苹果Web浏览器做得更多。