Open monoDevelop and select Start a New Solution.
Select the iphone Window-based Project name firstViewController. OK.
Then, press OK to automatically create the following files,
Main. cs content
Using System;
Using System. Collections. Generic;
Using System. Linq;
Using MonoTouch. Foundation;
Using MonoTouch. UIKit;
Namespace FirstViewController
{
Public class Application
{
Static void Main (string [] args)
{
UIApplication. Main (args );
}
}
// The name AppDelegate is referenced in the MainWindow. xib file.
Public partial class AppDelegate: UIApplicationDelegate
{
// This method is invoked when the application has loaded its UI and its ready to run
Public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
// If you have defined a view, add it here:
// Window. AddSubview (navigationController. View );
Window. MakeKeyAndVisible ();
Return true;
}
// This method is required in iPhoneOS 3.0
Public override void OnActivated (UIApplication application)
{
}
}
}
The FinishedLaunching method rewritten here. If the FinishedLaunching method does not return within 10 s, iso will close the application! Not to add too much code here!
Add an iPhone View with Controller. Choose iPhone and iPad from file> new> file> iPhone View with Controller.
Enter first, and press OK
Expand first. xib IN Solution
Double-click first. xib. cs
Add the following code
View plain
Private void butonClickFunction (object sender, EventArgs e)
{
(UIButton) sender). SetTitle ("clicked! ", UIControlState. Normal );
}
Public override void ViewDidLoad ()
{
Button2 = UIButton. FromType (UIButtonType. RoundedRect );
Button2.Frame = new System. Drawing. RectangleF (100f, 20f, 60f, 40f );
Button2.SetTitle ("click", UIControlState. Normal );
Button2.TouchUpInside + = new System. EventHandler (butonClickFunction );
This. View. AddSubview (button2 );
Base. ViewDidLoad ();
}
The butonClickFunction method is called when a button is clicked.
The ViewDidLoad () method is used to override the ViewDidLoad method, which is triggered when the view is loaded. In this method, you can load some controls and initialization operations. Here we add a UIbuttion, here, button2 adds the declaration in the class, UIButtion button2,
UIButton. FromType (UIButtonType. RoundedRect );
Here, the UIButtonType. RoundedRect is near back to a circle edge button, that is, the standard iso button.
Button. Frame = new System. Drawing. RectangleF (X in the upper left corner, Y in the upper left corner, width, and height)
Button2.SetTitle ("click", UIControlState. Normal); set the title,
Button2.TouchUpInside + = new System. EventHandler (butonClickFunction); set the event
This. View. AddSubview (button2); add button2 to the current view as a sub view
Base. viewDidLoad (); call the viewDidLoad of the parent class. In xcode, the parent class method is called in the subclass, which often appears. base is called in the real-column Class. init. They are all NSObject subclasses.
Return to main. cs
Add code in FinishedLaunching
Public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
// If you have defined a view, add it here:
// Window. AddSubview (navigationController. View );
First f = new first ();
Window. AddSubview (f. View );
Window. MakeKeyAndVisible ();
Return true;
}
Build and run
From ssihc0's column