zoukankan      html  css  js  c++  java
  • Monotouch几个常用控件的实例代码

    一、导航条 UINavigationController
      1. 简介:主要用于页面的导航,可以用于跳转页面及页面使用导航条上的按钮。初次运行程序 加载UINavigationController 
         1 public override bool FinishedLaunching(UIApplication app, NSDictionary options) {
         2             window = new UIWindow(UIScreen.MainScreen.Bounds);
         3             //NavMainViewController继承自UINavigationController
         4             viewController = new NavMainViewController();
         5             //程序开始运行时会将NavMainViewController作为主界面。
         6             //而NavMainViewController通过PushViewController方法显示要呈现的uiviewcontroller页面
         7             window.RootViewController = viewController;
         8             window.MakeKeyAndVisible();
         9             return true;
        10     }
      2. 跳转页面的代码:
         1     public class NavMainViewController:UINavigationController
         2     {
         3         public override void ViewDidLoad ()
         4         {
         5             base.ViewDidLoad ();
         6             //MusicPlayView是显示程序的主界面  继承自UIViewController
         7             this.PushViewController(new MusicPlayView(),true);
         8             //默认导航条的导航栏不显示
         9             this.NavigationBarHidden=true; 
        10         }
        11     }
      3. 使用导航条顶部按钮的代码:
         1             //创建UIBarbuttonItem
         2             UIBarButtonItem barEvaluate=new UIBarButtonItem();
         3             barEvaluate.Title="评价我们";
         4             barEvaluate.Style=UIBarButtonItemStyle.Bordered;
         5             barEvaluate.Clicked+=(sender,e)=>{
         6                 //打开应用商店
         7                 var url="http://itunes.apple.com/";
         8                 UIApplication.SharedApplication.OpenUrl(NSUrl.FromString(url));
         9             };
        10             //设置头部导航条的右侧按钮    
        11             this.NavigationItem.RightBarButtonItem=barEvaluate;
      4. 使用导航条底部按钮的代码:
         1 //使用UIBarButtonSystemItem实例化 点击底部工具栏btnPrevious时会有高亮效果
         2     UIBarButtonItem btnPrevious=new UIBarButtonItem(UIBarButtonSystemItem.Rewind);
         3     btnPrevious.Clicked+=(sender,e)=>{
         4 
         5     };
         6     //用于调整按钮间的间距控件
         7     UIBarButtonItem btnSpace=new UIBarButtonItem(UIBarButtonSystemItem.FixedSpace);
         8     //每个Item的默认Size为30*30
         9     btnSpace.Width=this.View.Frame.Width/2-30f;
        10     UIBarButtonItem btnNext=new UIBarButtonItem(UIBarButtonSystemItem.FastForward);
        11     btnNext.Clicked+=delegate{
        12 
        13     };
        14     this.ToolbarItems=new UIBarButtonItem[]{btnSpace,btnPrevious,btnSpace,btnNext};
        15     //显示底部工具栏
        16     this.NavigationController.ToolbarHidden=false;
        17     //调整顶部和底部工具栏的显示样式
        18     this.NavigationController.NavigationBar.BarStyle=UIBarStyle.Black;
        19     this.NavigationController.NavigationBar.Opaque=true;
        20     this.NavigationController.Toolbar.BarStyle=UIBarStyle.Black;
        21     this.NavigationController.Toolbar.Opaque=true;
      5. 备注:当你的页面使用或继承了UINavigationController,那页面中this.NavigationController则不为空。
    二、弹出UIPopoverController
      1. 简介:UIPopoverController主要有弹出窗口的作用。其作为容器,将要弹出的页面包含在其内部。
      2. 弹出代码:
                    barEvaluate.Clicked+=(sender,e)=>{
                        // 实例化要显示的UIViewController
                        SystemSetView systemView=new SystemSetView();
                        if(popOverCtrl==null){
                            popOverCtrl=new UIPopoverController(systemView);
                            //设置要弹出窗口的大小
                            popOverCtrl.PopoverContentSize=new SizeF(200f,500f);
                        }
                        //通过导航栏的按钮呈现
                        popOverCtrl.PresentFromBarButtonItem((UIBarButtonItem)sender,UIPopoverArrowDirection.Any,true);
                    };
    三、UIScrollView
      1. 简介:可以作为容器,进行页面的左右和上下滑动,支持缩放.
      2. 使用UIScrollView的代码,实现图片展的效果:
         1     //实例化
         2     var  _scView = new UIScrollView(this.View.Frame);
         3     this._scView.PagingEnabled = true;
         4     this._scView.ShowsHorizontalScrollIndicator = false;
         5     this._scView.ShowsVerticalScrollIndicator = false;
         6     this._scView.Layer.BorderWidth = 2;
         7     this._scView.Scrolled+=delegate{
         8         int curPage=((int)this._scView.ContentOffset.X+(int)LeftMarginIncrement/2)/(int)LeftMarginIncrement;
         9         if(curPage==_currentPageIndex || curPage>20 ||curPage<0)
        10         {
        11             return;
        12         }
        13         _currentPageIndex=curPage;
        14     };
        15     //设置要显示的内容
        16     for(int i = 0; i <=20; i++) {
        17         UIView myPictureView=new UIView(new RectangleF(ViewLeftMargin,ViewTopMargin,ViewWidth,ViewHeight));
        18         UIImageView myPictureImg=new UIImageView(new RectangleF(PicLeftMargin,PicTopMargin, PicWidth,PicHeight));
        19         myPictureImg.Image=UIImage.FromFile(string.Format("Resource/Img/{0}.jpg",i+1));
        20         myPictureView.AddSubview(myPictureImg);
        21         this._pageViews.Add(myPictureView);
        22         ViewLeftMargin=ViewLeftMargin+LeftMarginIncrement;
        23     }
        24     //
        25     _scView.AddSubviews(_pageViews.ToArray());
        26     this.View = this._scView;
        27     //设置需要显示的内容的大小
        28     this._scView.ContentSize = new SizeF(  _pageViews.Count* ViewWidth, ViewHeight );
        29     //设置当前显示的内容 根据内容的偏移量来定位
        30     this._scView.ContentOffset = new PointF(_currentPageIndex * this.ViewWidth, 0);

  • 相关阅读:
    【Gamma】Scrum Meeting 5
    【Gamma】Scrum Meeting 4
    【Gamma】Scrum Meeting 3
    团队贡献分汇总
    【Gamma】Scrum Meeting 2
    【Gamma】 Scrum Meeting 1
    Beta阶段测试报告
    From scipy.misc import imread 中 ImportError: cannot import name imread的解决方法
    【软件工程】结对项目
    【软件工程】第一次阅读作业
  • 原文地址:https://www.cnblogs.com/flowwind/p/3020760.html
Copyright © 2011-2022 走看看