首先要改一下 在你工程目录下的
test1.csproj
test1是我的工程名 用文本工具打开这个文件
以下是基中的一些内容
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">iPhoneSimulator</Platform>
<ProductVersion>9.0.21022</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{E960BCE9-5983-47D2-B32A-76CA18C468CA}</ProjectGuid>
<ProjectTypeGuids>{E613F3A2-FE9C-494F-B74E-F63BCB86FEA6};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<OutputType>Exe</OutputType>
<RootNamespace>test1</RootNamespace>
<MainNibFile>MainWindow.xib</MainNibFile>
<AssemblyName>test1</AssemblyName>
<MtouchMinimumOS>3.0</MtouchMinimumOS>
<TargetFrameworkVersion>v1.0</TargetFrameworkVersion>
</PropertyGroup>
要把
<MainNibFile>MainWindow.xib</MainNibFile> 删除了
在MonoDevelop 里把MainWindow.xib 相关的东西也删除了
以下是代码
main.cs
using System;
//using System.Collections.Generic;
//using System.Linq;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
namespace test1
{
[Register ("AppDelegate1")]
// The name AppDelegate is referenced in the MainWindow.xib file.
public class AppDelegate1 : UIApplicationDelegate
{
UIWindow window;
// 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 = new UIWindow (UIScreen.MainScreen.Bounds);
var activit= new UIActivityIndicatorView ();
var frame3=new System.Drawing.RectangleF(35f,130f,40f,40f);
activit.Frame=frame3;
activit.ActivityIndicatorViewStyle=UIActivityIndicatorViewStyle.WhiteLarge;
activit.HidesWhenStopped=true;
window.AddSubview(activit);
var button =UIButton.FromType(UIButtonType.RoundedRect);
var frame=new System.Drawing.RectangleF(35f,30f,250f,40f);
button.Frame=frame;
button.SetTitle("start",UIControlState.Normal);
button.TouchUpInside += (sender, e) => {
button.SetTitle("start",UIControlState.Normal);
activit.StartAnimating();
};
window.AddSubview(button);
var button1 =UIButton.FromType(UIButtonType.RoundedRect);
var frame1=new System.Drawing.RectangleF(35f,80f,250f,40f);
button1.Frame=frame1;
button1.SetTitle("stop",UIControlState.Normal);
button1.TouchUpInside += (sender, e) => { button1.SetTitle("stop",UIControlState.Normal); activit.StopAnimating();};
window.AddSubview(button1);
window.MakeKeyAndVisible ();
return true;
}
}
public class Application
{
static void Main (string[] args)
{
UIApplication.Main (args,null,"AppDelegate1");
}
}
}
运行的结果