新建一个空工程,如图

新建类
using System;
using UIKit;
namespace TabbedApplication
{
public class TabController : UITabBarController
{
UIViewController tab1,tab2,tab3;
public TabController ()
{
tab1 = new UIViewController();
tab1.Title = "Green";
tab1.View.BackgroundColor = UIColor.Green;
tab1.TabBarItem = new UITabBarItem (UITabBarSystemItem.Favorites, 0);
tab2 = new UIViewController();
tab2.Title = "Orange";
tab2.View.BackgroundColor = UIColor.Orange;
tab2.TabBarItem.Image = UIImage.FromFile ("second.png");
tab2.Title = "Second";
tab3 = new UIViewController();
tab3.Title = "Red";
tab3.View.BackgroundColor = UIColor.Red;
tab3.TabBarItem.BadgeValue = "Hi";
var tabs = new UIViewController[] {
tab1, tab2, tab3
};
ViewControllers = tabs;
}
}
}
修改 AppDelegate.cs
using System;
using System.Collections.Generic;
using System.Linq;
using Foundation;
using UIKit;
namespace TabbedApplication
{
// The UIApplicationDelegate for the application. This class is responsible for launching the
// User Interface of the application, as well as listening (and optionally responding) to
// application events from iOS.
[Register ("AppDelegate")]
public partial class AppDelegate : UIApplicationDelegate
{
// class-level declarations
UIWindow window;
TabController tabController;
//
// This method is invoked when the application has loaded and is ready to run. In this
// method you should instantiate the window, load the UI into it and then make the window
// visible.
//
// You have 17 seconds to return from this method, or iOS will terminate your application.
//
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
// create a new window instance based on the screen size
window = new UIWindow (UIScreen.MainScreen.Bounds);
// If you have defined a root view controller, set it here:
// window.RootViewController = myViewController;
tabController=new TabController();
window.RootViewController = tabController;
// make the window visible
window.MakeKeyAndVisible ();
return true;
}
}
}
运行程序


