monotouch:第一次启动自己创建的界面与跳转

  我的工作经验并不久,所以我记的东西可能也比较琐碎,这是第二个做的monotouch的项目,第一个项目开发的时候挺急的,并没有什么记录,现在要做第二个项目了,两三个月没写,发现忘了差不多了,很多东西都要重新查资料。

  创建第一个iPhoneViewController:FirstView

     

  在项目根目录下有个AppDelegate.cs文件。更改FinishedLaunching方法体:

  

              UIWindow window;

        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            window = new UIWindow(UIScreen.MainScreen.Bounds);

            var rootNavigationController = new UINavigationController ();

            rootNavigationController.PushViewController(new FristView(), false);//----设置启动页

            this.window.RootViewController = rootNavigationController;

            window.MakeKeyAndVisible();

            return true;
        }    

  跳转页面就更简单了,在FirstView.cs的ViewDidLoad()添加代码:(加了一点按钮属性,这些看个人必要需不需要设置了)

       UIButton btn1 = new UIButton ();
            btn1.Frame = new RectangleF (10, 100, 70, 30);
            btn1.SetTitle("跳转",UIControlState.Normal);
            btn1.Layer.BorderColor = new MonoTouch.CoreGraphics.CGColor(0.8f, 0.8f, 0.8f);//设置边框颜色
            btn1.Layer.BorderWidth = 1f;//设置边框宽度
            btn1.Layer.CornerRadius = 5f;//设置边框圆角
            btn1.SetTitleColor(UIColor.Black, UIControlState.Normal);//设置按钮文本颜色
            btn1.HorizontalAlignment=UIControlContentHorizontalAlignment.Center;//设置按钮文本对齐方向
            btn1.Font = UIFont.FromName("Arial", 14f);

            btn1.TouchUpInside += (sender, e) => {
                SecondView view=new SecondView();
                this.NavigationController.PushViewController(view, true);
            };
            View.AddSubview (btn1);            


效果:

 

回退按钮显示文本更改:

			this.NavigationItem.SetLeftBarButtonItem(new UIBarButtonItem("返回", UIBarButtonItemStyle.Plain,
				(sender, e) =>
				{
					this.NavigationController.PopViewControllerAnimated(true);
				}), true);
			

 效果:

 

posted on 2015-04-22 16:39  墨色枫雪  阅读(111)  评论(0)    收藏  举报