C# iphone开发 MontTouch 使用代码创建UIWindow

首先要改一下 在你工程目录下的

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");
		}
	}
	

}


运行的结果




  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值