C# iphone MontTouch UIProgressView 的使用

想学用C#开发iphone 的就加入 QQ群:178290571 ,让我们共同进步吧!

C# MonoTouch for iphone 开发blog  http://blog.csdn.net/ssihc0/

MonoDevelop 版本:2.8.0

MonoTouch 版本:4.2.2


UIProgressView 向用户传达进度信息时。使用这个控件。它提供了一个从左到右逐渐填满的进度条。

常用的属性:

  Progress 当前的进度值,取值范围(0.0f-1.0f)

  Style 进度条的样式  使用UIProgressViewStyle枚举选择   Default ,Bar 其中的一种样式。


下面是方法和属性:


新建一个工程名为Progress 打开ProgressViewController


添加下面代码:

public partial class ProgressViewController : UIViewController
	{
		UIProgressView  progress;
		public ProgressViewController (string nibName, NSBundle bundle) : base (nibName, bundle)
		{
		}
		
		public override void DidReceiveMemoryWarning ()
		{
			// Releases the view if it doesn't have a superview.
			base.DidReceiveMemoryWarning ();
			
			// Release any cached data, images, etc that aren't in use.
		}
		
		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();
			progress= new UIProgressView(new System.Drawing.RectangleF(30f,35f,200f,45f	));
			progress.Style=UIProgressViewStyle.Default;
			progress.Progress=0.0f;
			NSTimer.CreateRepeatingScheduledTimer(1/10,delegate {
				this.timer_call();
			} );
		
			this.View.AddSubview(progress);
			
			//any additional setup after loading the view, typically from a nib.
		}
		
		
		private void timer_call()
		{
			if (progress.Progress>=1.0f) {
				progress.Progress=0.0f;
			}
			progress.Progress += 0.0002f;
		}
		
		public override void ViewDidUnload ()
		{
			base.ViewDidUnload ();
			
			// Release any retained subviews of the main view.
			// e.g. myOutlet = null;
		}
		
		public override bool ShouldAutorotateToInterfaceOrientation (UIInterfaceOrientation toInterfaceOrientation)
		{
			// Return true for supported orientations
			return (toInterfaceOrientation != UIInterfaceOrientation.PortraitUpsideDown);
		}
	}

代码分析:

progress.Style=UIProgressViewStyle.Default;   设置样式
            progress.Progress=0.0f; 设置进度开始的指示值

      下面是建了一个定时器
            NSTimer.CreateRepeatingScheduledTimer(1/10,delegate {
                this.timer_call();}


  下面是定时器调用的function
        private void timer_call()
        {
            if (progress.Progress>=1.0f) {
                progress.Progress=0.0f;
            }
            progress.Progress += 0.0002f;
        }

运行结果:




源代码:

下载

下载后把gif 改成zip
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值