简体   繁体   English

如何以编程方式创建进度条?

[英]How to create progress bar programmatically?

I created a view with a progress bar with an IBOutlet. 我创建了一个带有IBOutlet进度条的视图。 Whenever I rotate the view to landscape mode, it is not rotated. 每当我将视图旋转到横向模式时,都不会旋转。 So, I need to create the progress bar programmatically. 因此,我需要以编程方式创建进度条。

How can I do this? 我怎样才能做到这一点?

UIProgressView *progressView = [[UIProgressView alloc] init];
progressView.frame = CGRectMake(100,100,100,20);
[self.view addSubview:progressView];

Should get you started. 应该让您开始。

I would read up on views and view controllers in Apple's documentation. 我将阅读Apple文档中的视图和视图控制器。 The View Programming Guide for iPhone OS goes into quite a bit of detail for what you want to do. iPhone OS的《 View编程指南》详细介绍了您要执行的操作。 If you have not read the iPhone Application Programming Guide and the iPhone Development Guide I would do so first. 如果您还没有阅读《 iPhone应用程序编程指南》和《 iPhone开发指南》,请先阅读。

All of these documents are available on developer.apple.com, and also in the help system of Xcode. 所有这些文档都可以在developer.apple.com以及Xcode的帮助系统中找到。

您可以通过以下代码将进度条旋转到垂直方向:

progressView.transform= CGAffineTransformMakeRotation( M_PI * 0.5 );

you have to set the property of size in IB then is't work fine see in below image 您必须在IB中设置size属性,然后无法正常工作,请参见下图 替代文字

this work for both orientations 这两个方向的工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM