您的位置:首页 > 产品设计 > UI/UE

C# iphone MontTouch UIProgressView 的使用

2011-10-11 18:49 363 查看
想学用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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: