想学用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