2011-12-14 5 views
0

아래 이미지에 표시된 UI 구성 요소를 만들어야하고 또한 알아야합니다.이 새로운 UI 구성 요소는 무엇이며 어떻게 코딩합니까?

  1. 무엇이라고 부릅니까? (회색 상자)
  2. 어떻게 이미지 나 다른 UI 구성 요소를 추가합니까?
  3. 이것을 만들 수있는 샘플 코드 또는 자습서가 있습니까?

이미지는

enter image description here

+0

은 단순한 투명한 화면처럼 보입니다. 아니? – Novarg

답변

1

진행률 표시 줄이 없습니다. 그런 식으로 enter image description here
를하고 간다 : 나는 PDColoredProgressViewThree20

그것은 다음과 같습니다 사용하여 하나를 만들었습니다

.H 파일을

#import <UIKit/UIKit.h> 
#import "PDColoredProgressView.h" 

@interface SVProgressHudView : UIView<PDColoredProgressViewDelegate>{ 
    UIView*     bgView; 
    UILabel*    _titleLabel; 
    PDColoredProgressView* _progress; 
    UILabel*    _percentLabel; 
    UILabel*    _subtitleLabel; 
    NSUInteger    _numOfSteps; 
    NSUInteger    _currentStep; 
    CGFloat     _currentStepProgress; 
    CGFloat     _oneStepPart; 
    CGFloat     _extraStepPart; 
    BOOL     _removeFromSuperViewOnHide; 
    BOOL     _extraStep; 
    UIButton*    _closeButton; 
} 

@property (nonatomic, assign)BOOL removeFromSuperViewOnHide; 

+(SVProgressHudView *)hudAddedTo:(UIView *)view withTitle:(NSString*)title numberOfSteps:(NSUInteger)numberOfSteps extraStep:(BOOL)exrta; 
+(BOOL)isThereHudAddedToView:(UIView*)view; 

-(id)initWithFrame:(CGRect)frame title:(NSString*)title numberOfSteps:(NSUInteger)numberOfSteps extraStep:(BOOL)exrta; 

-(void)show:(BOOL)animated; 
-(void)hide:(BOOL)animated; 
-(void)setCurrentStepProgress:(CGFloat)currentProgress animated:(BOOL)animated; 
-(void)setCurrentStep:(NSUInteger)currentStep animated:(BOOL)animated; 
-(void)setExtraStepProgress:(CGFloat)progress animated:(BOOL)animated; 

-(void)setSuccessSubtitle:(NSString*)subtitle; 

-(void)setCloseButtonTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents; 

@end 

하는 .m 파일 :

#import "SVProgressHudView.h" 
#import <QuartzCore/QuartzCore.h> 
#import <Three20/Three20.h> 
#import "Three20UI/UIViewAdditions.h" 
#import "Globals.h" 
#import "SVGradientButton.h" 

#define kMinimumWidth   100 
#define kMinimumHeight   100 

#define kHorizontalMargin  20 
#define kVerticalMargin   20 
#define kLittleVerticalMargin 7 
#define kCornerRadius   10 

#define kOpacity    0.85 

static UIFont* regularSubtextFont; 
static UIFont* successSubtextFont; 

@interface SVProgressHudView(Private) 

-(void)done; 

@end 

@implementation SVProgressHudView 

@synthesize 
removeFromSuperViewOnHide = _removeFromSuperViewOnHide; 

+(void)initialize{ 
    regularSubtextFont = [[UIFont systemFontOfSize:[UIFont systemFontSize]+3]retain]; 
    successSubtextFont = [[UIFont systemFontOfSize:[UIFont systemFontSize]+3]retain]; 
} 

- (id)initWithFrame:(CGRect)frame{ 
    CGFloat minimumWidth = kMinimumWidth+kHorizontalMargin*2; 
    CGFloat minimumHeight = kMinimumHeight + kVerticalMargin*2; 
    //to ensure we can place it inside that frame 
    if(frame.size.width>=minimumWidth && frame.size.height >=minimumHeight){ 
     self = [super initWithFrame:frame]; 
     if (self) { 
      CGFloat bgWidth = frame.size.width - kHorizontalMargin*2; 
      bgView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, bgWidth, kMinimumHeight)]; 
      bgView.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:kOpacity]; 
      bgView.clipsToBounds = YES; 
      bgView.center = CGPointMake(self.width/2.0, self.height/2.0); 
      bgView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleBottomMargin; 
      bgView.layer.cornerRadius = 10.0; 
      bgView.layer.masksToBounds = YES; 
      [self addSubview:bgView]; 

      UIImage* closeImage = [UIImage imageNamed:@"xButton.png"]; 
      _closeButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
      _closeButton.frame = CGRectMake(0, 0, closeImage.size.width*1.5, closeImage.size.height*1.5); 
      [_closeButton setBackgroundImage:closeImage forState:UIControlStateNormal]; 
      [_closeButton addTarget:self action:@selector(closeFired) forControlEvents:UIControlEventTouchUpInside]; 
      _closeButton.right = bgView.right +_closeButton.width/3; 
      [self addSubview:_closeButton]; 

      _titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(kHorizontalMargin, kVerticalMargin, bgWidth-kHorizontalMargin*2, 20)]; 
      _titleLabel.textColor = [UIColor whiteColor]; 
      _titleLabel.textAlignment = UITextAlignmentCenter; 
      _titleLabel.backgroundColor = [UIColor clearColor]; 
      [bgView addSubview:_titleLabel]; 

      _progress = [[PDColoredProgressView alloc]initWithProgressViewStyle:UIProgressViewStyleDefault]; 
      _progress.delegate = self; 
      [_progress setBackgroundColor:[UIColor clearColor]]; 
      [_progress setTintColor:[UIColor colorWithWhite:0.5 alpha:1.0]];//[Globals defaultTintColorForNavBar]]; 
      [bgView addSubview:_progress]; 
      [_progress sizeToFit]; 
      _progress.top = _titleLabel.bottom+kVerticalMargin; 
      _progress.width = bgWidth-kHorizontalMargin*2-kCornerRadius*2; 
      _progress.left = kHorizontalMargin+kCornerRadius; 
      _progress.progress = 0.0; 

      _percentLabel = [[UILabel alloc]initWithFrame:CGRectMake(_progress.left, _progress.bottom+kLittleVerticalMargin, _progress.width/2, 20)]; 
      _percentLabel.textColor = [UIColor whiteColor]; 
      _percentLabel.textAlignment = UITextAlignmentLeft; 
      _percentLabel.backgroundColor = [UIColor clearColor]; 
      _percentLabel.font = regularSubtextFont; 
      [bgView addSubview:_percentLabel]; 

      _subtitleLabel = [[UILabel alloc]initWithFrame:CGRectMake(_percentLabel.right, _percentLabel.top, _percentLabel.width, 20)]; 
      _subtitleLabel.textColor = [UIColor whiteColor]; 
      _subtitleLabel.textAlignment = UITextAlignmentRight; 
      _subtitleLabel.backgroundColor = [UIColor clearColor]; 
      _subtitleLabel.font = regularSubtextFont; 
      [bgView addSubview:_subtitleLabel]; 

      bgView.height = _subtitleLabel.bottom+kVerticalMargin; 
      bgView.center = self.center; 

      _closeButton.top = bgView.top - _closeButton.height/3; 

      _extraStep = NO;    
     } 
    } 
    return self; 
} 

-(id)initWithFrame:(CGRect)frame title:(NSString*)title numberOfSteps:(NSUInteger)numberOfSteps extraStep:(BOOL)exrta{ 
    self = [self initWithFrame:frame]; 
    if(self){ 
     _titleLabel.text = title; 
     _numOfSteps = numberOfSteps; 
     _extraStep = exrta; 
     if(_extraStep){ 
      CGFloat stepPart = 1.0/numberOfSteps; 
      _extraStepPart = stepPart/10; 
      _oneStepPart = (1.0-_extraStepPart)/numberOfSteps; 
     }else{ 
      _oneStepPart = 1.0/numberOfSteps; 
     } 
     [self setCurrentStep:0 animated:NO]; 
    } 
    return self; 
} 

-(void)dealloc{ 
    TT_RELEASE_SAFELY(_titleLabel); 
    TT_RELEASE_SAFELY(_subtitleLabel); 
    TT_RELEASE_SAFELY(_percentLabel); 
    TT_RELEASE_SAFELY(_progress); 
    TT_RELEASE_SAFELY(bgView); 
    [super dealloc]; 
} 

#pragma mark - Showing and Hiding 

- (void)show:(BOOL)animated { 
    self.alpha = 0.0; 
    // Fade in 
    if (animated) { 
     [UIView animateWithDuration:0.3 
         animations:^{ 
          self.alpha = 1.0; 
         }]; 
    }else { 
     self.alpha = 1.0; 
    } 
} 

- (void)hide:(BOOL)animated { 
    if (animated) { 
     [UIView animateWithDuration:0.3 
         animations:^{ 
          self.alpha = 0.2; 
         } 
         completion:^(BOOL finished) { 
          [self done]; 
         }]; 
    } 
    else { 
     [self done]; 
    } 
} 

#pragma mark - Private Methods 

- (void)done { 
    self.alpha = 0.0; 
    if (_removeFromSuperViewOnHide) { 
     [self removeFromSuperview]; 
    } 
} 

#pragma mark - Public Methods 

+ (BOOL)isThereHudAddedToView:(UIView*)view{ 
    for (UIView *v in [view subviews]) { 
     if ([v isKindOfClass:[SVProgressHudView class]]) { 
      return YES; 
     } 
    } 
    return NO; 
} 

+ (SVProgressHudView *)hudAddedTo:(UIView *)view withTitle:(NSString*)title numberOfSteps:(NSUInteger)numberOfSteps extraStep:(BOOL)exrta{ 
    SVProgressHudView *hud = [[SVProgressHudView alloc] initWithFrame:view.bounds title:title numberOfSteps:numberOfSteps extraStep:exrta]; 
    hud.alpha = 0.0; 
    [view addSubview:hud]; 
    return [hud autorelease]; 
} 

-(void)setCurrentStepProgress:(CGFloat)currentStepProgress animated:(BOOL)animated{ 
    if(currentStepProgress < 0.0){ 
     currentStepProgress = 0.0; 
    } 
    if(currentStepProgress > 1.0){ 
     currentStepProgress = 1.0; 
    } 
    CGFloat currentProgress = _oneStepPart*_currentStep; 
    currentProgress += _oneStepPart*currentStepProgress; 
    [_progress setProgress:currentProgress animated:animated]; 
} 

-(void)setCurrentStep:(NSUInteger)currentStep animated:(BOOL)animated{ 
    if(currentStep > _numOfSteps){ 
     currentStep = _numOfSteps; 
    } 
    _currentStep = currentStep; 
    _subtitleLabel.text = [NSString stringWithFormat:@"%d/%d",currentStep+1,_numOfSteps]; 
    _subtitleLabel.font = regularSubtextFont; 
    [self setCurrentStepProgress:0.0 animated:animated]; 
} 

-(void)setExtraStepProgress:(CGFloat)progress animated:(BOOL)animated{ 
    if(progress < 0.0){ 
     progress = 0.0; 
    } 
    if(progress > 1.0){ 
     progress = 1.0; 
    } 
    if(progress == 1.0){ 
     //hide the close button 
     _closeButton.hidden = YES; 
    } 
    CGFloat currentProgress = _oneStepPart*_numOfSteps; 
    currentProgress += _extraStepPart*progress; 
    [_progress setProgress:currentProgress animated:animated]; 
} 

-(void)progressUpdated:(PDColoredProgressView *)progressView toValue:(CGFloat)value{ 
    _percentLabel.text = [NSString stringWithFormat:@"%d%%",(int)(value*100)]; 
} 

-(void)setSuccessSubtitle:(NSString *)subtitle{ 
    [_progress setProgress:1.0 animated:YES]; 
    _subtitleLabel.text = subtitle; 
    _subtitleLabel.font = successSubtextFont; 
} 

-(void)closeFired{ 
    [_progress cancelAnimations]; 
} 

-(void)setCloseButtonTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents{ 
    [_closeButton addTarget:target action:action forControlEvents:controlEvents]; 
} 

@end 

특정 p 용으로 제작되었으므로 완벽하지 않습니다. 그러나 그것은 일을하고있다.
도움이 되길 바랍니다.
해피 코딩.

3

그게 MBProgressHUD 생각합니다. 질문에 대한

대답에

https://github.com/jdg/MBProgressHUD

+0

'UIProgressHUD'에 관한 비디오 튜토리얼을 보았는데, 애플은 개인 API 때문에 그것을 거부 할 것이라고합니다. 이게 어떻게 진실입니까? 'UIProgressHUD'는 애플도이를 거부 할 것인가? http://www.youtube.com/watch?v=fhBcBbmlIsI – Illep

+0

'UIProgressHUD'는 비공개 API이며, 애플이 앱을 사용한다면 반드시 거부 할 것입니다. –

+0

그러나 오픈 소스 대안 인'MBProgressHUD'와'ATMHUD'가 있습니다. –

4

은 :

1) 그것은 무엇이라고

? 내가 UIView와 함께 갈 것

  • - 그것의 cornerRadius와는 CALayer 세트 및 반투명 배경 색상입니다.

2) 이미지 또는 다른 UI 구성 요소를 어떻게 추가합니까?

  • [myview addSubview: someSubview];

3)이 만드는 사용할 수있는 샘플 코드 또는 자습서가 있습니까?

  • 실제로는 Apple docs을 읽을 필요가있는 것 같습니다.
관련 문제