2012-02-29 2 views
2

사용자가 단추를 누를 때마다 새 UI 요소 (UIProgressView 막대)를 별도의 UIViewController에서 만들 수 있기를 바랍니다.프로그래밍 방식으로 UI 요소를 만드는 방법

어떻게해야합니까? 단순히, ALLOC 및 초기화를 사용하여 프레임을 설정하는 문제이다,

UIView *view = [[UIView alloc] initWithFrame:CGRect]; 
// set the property of the view here 
// ... 

// finally add your view 
[ViewController.view addSubView:view]; 
+3

무슨 뜻인지 모르겠습니다. viewController1의 액션에 따라 viewController2가 표시 될 때 진행 뷰를 표시하려고합니까? 그렇다면 viewController2가 수신하는 알림을 사용할 수 있습니다. 알림을 받으면 진행률보기를 만듭니다. –

+0

정확히이 ... 알림을 사용하는 것과 appDelegate를 사용하는 것이 어떻게 다른가요? – iggy2012

답변

4

프로그래밍 UIProgressView를 만들려면 및 :

+0

고맙습니다. – iggy2012

+0

문제 없습니다. UI 코드 작성 방법을 모르는 경우 최대한 빨리 뼈대를 만드는 것이 좋습니다! – CodaFi

1

이 가이드 UI 요소의 대부분 https://developer.apple.com/library/ios/#DOCUMENTATION/WindowsViews/Conceptual/ViewPG_iPhoneOS/CreatingViews/CreatingViews.html

읽기는 다음과 같이 생성 다음과 같이 하위보기를 추가하십시오.

//.h 

#import <UIKit/UIKit.h> 

@interface ExampleViewController : UIViewController { 

    //create the ivar 
    UIProgressView *_progressView; 

} 
/*I like to back up my iVars with properties. If you aren't using ARC, use retain instead of strong*/ 
@property (nonatomic, strong) UIProgressView *progressView; 

@end 

//.m 

@implementation 
@synthesize progressView = _progressView; 

-(void)viewDidLoad { 
    /* it isn't necessary to create the progressView here, after all you could call this code from any method you wanted to and it would still work*/ 
    //allocate and initialize the progressView with the bar style 
    self.progressView = [[UIProgressView alloc]initWithProgressViewStyle:UIProgressViewStyleBar]; 
    //add the progressView to our main view. 
    [self.view addSubview: self.progressView]; 
    //if you ever want to remove it, call [self.progressView removeFromSuperView]; 

} 
관련 문제