0

사용자 지정 UIView 컨트롤러 내에서 PaintCode progressView를 구현하여 여러 가지 테스트를하고 있습니다 ... 이 절차는 UIView 개체를 배치하고 해당 클래스 progressview를 변경하여 viewcontroller의 뷰 내에서의 커스터마이즈.PaintCode로 UiProgressView 사용자 지정

지금까지 좋은 점은 프로젝트를 컴파일 할 때 뷰 콘트롤러에 포함 된보기의 크기에 따라 항상 회색 원이나 직사각형을 가짐으로써 내 progressview를 개인화 한 것입니다. ...

내가 삽입 한 코드가 단순한 사용자 정의 파일 인 ProgressView (하위 클래스 ProgressView)이기 때문에 내가 틀렸다고 이해하지 못합니다. 뷰 컨트롤러에서 '이 http://www.raywenderlich.com/it/44556/paintcode-tutorial-progress-bar-custom

당신이 내 문제를 해결하는 방법을 알아 아무것도 ...

내가 튜토리얼을 따라가 없다? Rory에게 도움을 주신 모든 분들께 감사드립니다.

- (void)drawRect:(CGRect)rect 
{ 
    //// General Declarations 
    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); 
    CGContextRef context = UIGraphicsGetCurrentContext(); 

    //// Color Declarations 
    UIColor* fillColor = [UIColor colorWithRed: 0.416 green: 0.416 blue: 0.416 alpha: 1]; 
    UIColor* strokeColor = [UIColor colorWithRed: 0.322 green: 0.322 blue: 0.322 alpha: 1]; 
    UIColor* shadowColor2 = [UIColor colorWithRed: 0.2 green: 0.2 blue: 0.2 alpha: 1]; 
    UIColor* shadowColor3 = [UIColor colorWithRed: 0.671 green: 0.671 blue: 0.671 alpha: 1]; 
    UIColor* fillColor2 = [UIColor colorWithRed: 0.247 green: 0.247 blue: 0.247 alpha: 1]; 
    UIColor* strokeColor2 = [UIColor colorWithRed: 0.188 green: 0.188 blue: 0.188 alpha: 1]; 
    UIColor* color = [UIColor colorWithRed: 0 green: 0.886 blue: 0 alpha: 1]; 

    //// Gradient Declarations 
    NSArray* outerRectGradientColors = [NSArray arrayWithObjects: 
             (id)strokeColor.CGColor, 
             (id)fillColor.CGColor, nil]; 
    CGFloat outerRectGradientLocations[] = {0, 1}; 
    CGGradientRef outerRectGradient = CGGradientCreateWithColors(colorSpace, (__bridge CFArrayRef)outerRectGradientColors, outerRectGradientLocations); 
    NSArray* gradientColors = [NSArray arrayWithObjects: 
           (id)strokeColor2.CGColor, 
           (id)fillColor2.CGColor, nil]; 
    CGFloat gradientLocations[] = {0, 1}; 
    CGGradientRef gradient = CGGradientCreateWithColors(colorSpace, (__bridge CFArrayRef)gradientColors, gradientLocations); 

    //// Shadow Declarations 
    UIColor* darkShadow = shadowColor2; 
    CGSize darkShadowOffset = CGSizeMake(3.1, 3.1); 
    CGFloat darkShadowBlurRadius = 5; 
    UIColor* lightShadow = shadowColor3; 
    CGSize lightShadowOffset = CGSizeMake(3.1, 3.1); 
    CGFloat lightShadowBlurRadius = 5; 

    //// Frames 
    CGRect progressIndicatorFrame = CGRectMake(-1, 0, 321, 47); 

    //// Subframes 
    CGRect group = CGRectMake(CGRectGetMinX(progressIndicatorFrame) + 10, CGRectGetMinY(progressIndicatorFrame) + 9, CGRectGetWidth(progressIndicatorFrame) - 25, 20); 
    CGRect activeProgressFrame = CGRectMake(CGRectGetMinX(group) + floor(CGRectGetWidth(group) * 0.00000 + 0.5), CGRectGetMinY(group) + floor(CGRectGetHeight(group) * 0.00000 + 0.5), floor(CGRectGetWidth(group) * 1.00000 + 0.5) - floor(CGRectGetWidth(group) * 0.00000 + 0.5), floor(CGRectGetHeight(group) * 1.00000 + 0.5) - floor(CGRectGetHeight(group) * 0.00000 + 0.5)); 

    //// Abstracted Attributes 
    CGRect progressTrackActiveRect = CGRectMake(CGRectGetMinX(activeProgressFrame) + 4, CGRectGetMinY(activeProgressFrame) + 5, CGRectGetWidth(activeProgressFrame) - 8, 10); 

    //// Progress Bar 
    { 
     //// Border Drawing 
     CGRect borderRect = CGRectMake(CGRectGetMinX(progressIndicatorFrame) + 2, CGRectGetMinY(progressIndicatorFrame) + 3, CGRectGetWidth(progressIndicatorFrame) - 5, 34); 
     UIBezierPath* borderPath = [UIBezierPath bezierPathWithRoundedRect: borderRect cornerRadius: 4]; 
     CGContextSaveGState(context); 
     CGContextSetShadowWithColor(context, darkShadowOffset, darkShadowBlurRadius, darkShadow.CGColor); 
     CGContextBeginTransparencyLayer(context, NULL); 
     [borderPath addClip]; 
     CGContextDrawLinearGradient(context, outerRectGradient, 
            CGPointMake(CGRectGetMidX(borderRect), CGRectGetMinY(borderRect)), 
            CGPointMake(CGRectGetMidX(borderRect), CGRectGetMaxY(borderRect)), 
            0); 
     CGContextEndTransparencyLayer(context); 

     ////// Border Inner Shadow 
     CGRect borderBorderRect = CGRectInset([borderPath bounds], -lightShadowBlurRadius, -lightShadowBlurRadius); 
     borderBorderRect = CGRectOffset(borderBorderRect, -lightShadowOffset.width, -lightShadowOffset.height); 
     borderBorderRect = CGRectInset(CGRectUnion(borderBorderRect, [borderPath bounds]), -1, -1); 

     UIBezierPath* borderNegativePath = [UIBezierPath bezierPathWithRect: borderBorderRect]; 
     [borderNegativePath appendPath: borderPath]; 
     borderNegativePath.usesEvenOddFillRule = YES; 

     CGContextSaveGState(context); 
     { 
      CGFloat xOffset = lightShadowOffset.width + round(borderBorderRect.size.width); 
      CGFloat yOffset = lightShadowOffset.height; 
      CGContextSetShadowWithColor(context, 
             CGSizeMake(xOffset + copysign(0.1, xOffset), yOffset + copysign(0.1, yOffset)), 
             lightShadowBlurRadius, 
             lightShadow.CGColor); 

      [borderPath addClip]; 
      CGAffineTransform transform = CGAffineTransformMakeTranslation(-round(borderBorderRect.size.width), 0); 
      [borderNegativePath applyTransform: transform]; 
      [[UIColor grayColor] setFill]; 
      [borderNegativePath fill]; 
     } 
     CGContextRestoreGState(context); 

     CGContextRestoreGState(context); 

     //// ProgressTrack Drawing 
     CGRect progressTrackRect = CGRectMake(CGRectGetMinX(progressIndicatorFrame) + 12, CGRectGetMinY(progressIndicatorFrame) + 12, CGRectGetWidth(progressIndicatorFrame) - 29, 14); 
     UIBezierPath* progressTrackPath = [UIBezierPath bezierPathWithRoundedRect: progressTrackRect cornerRadius: 7]; 
     CGContextSaveGState(context); 
     CGContextSetShadowWithColor(context, lightShadowOffset, lightShadowBlurRadius, lightShadow.CGColor); 
     CGContextBeginTransparencyLayer(context, NULL); 
     [progressTrackPath addClip]; 
     CGContextDrawLinearGradient(context, gradient, 
            CGPointMake(CGRectGetMidX(progressTrackRect), CGRectGetMinY(progressTrackRect)), 
            CGPointMake(CGRectGetMidX(progressTrackRect), CGRectGetMaxY(progressTrackRect)), 
            0); 
     CGContextEndTransparencyLayer(context); 

     ////// ProgressTrack Inner Shadow 
     CGRect progressTrackBorderRect = CGRectInset([progressTrackPath bounds], -darkShadowBlurRadius, -darkShadowBlurRadius); 
     progressTrackBorderRect = CGRectOffset(progressTrackBorderRect, -darkShadowOffset.width, -darkShadowOffset.height); 
     progressTrackBorderRect = CGRectInset(CGRectUnion(progressTrackBorderRect, [progressTrackPath bounds]), -1, -1); 

     UIBezierPath* progressTrackNegativePath = [UIBezierPath bezierPathWithRect: progressTrackBorderRect]; 
     [progressTrackNegativePath appendPath: progressTrackPath]; 
     progressTrackNegativePath.usesEvenOddFillRule = YES; 

     CGContextSaveGState(context); 
     { 
      CGFloat xOffset = darkShadowOffset.width + round(progressTrackBorderRect.size.width); 
      CGFloat yOffset = darkShadowOffset.height; 
      CGContextSetShadowWithColor(context, 
             CGSizeMake(xOffset + copysign(0.1, xOffset), yOffset + copysign(0.1, yOffset)), 
             darkShadowBlurRadius, 
             darkShadow.CGColor); 

      [progressTrackPath addClip]; 
      CGAffineTransform transform = CGAffineTransformMakeTranslation(-round(progressTrackBorderRect.size.width), 0); 
      [progressTrackNegativePath applyTransform: transform]; 
      [[UIColor grayColor] setFill]; 
      [progressTrackNegativePath fill]; 
     } 
     CGContextRestoreGState(context); 

     CGContextRestoreGState(context); 

     //// Group 
     { 
      //// ProgressTrackActive Drawing 
      UIBezierPath* progressTrackActivePath = [UIBezierPath bezierPathWithRoundedRect: progressTrackActiveRect cornerRadius: 5]; 
      [color setFill]; 
      [progressTrackActivePath fill]; 
     } 
    } 

    //// Cleanup 
    CGGradientRelease(outerRectGradient); 
    CGGradientRelease(gradient); 
    CGColorSpaceRelease(colorSpace); 
} 
+0

@JuJoDi 코코아 터치 질문에 코코아 태그를 사용하지 마십시오. 대신 코코아 터치 태그를 사용하십시오. –

답변

0

튜토리얼에는 아직 두 가지 변경 사항이 없습니다. 당신은 아이폰 OS를 사용하는 경우 이 줄

//// Frames 
CGRect progressIndicatorFrame = CGRectMake(-1, 0, 321, 47); 

//// Frames 
CGRect progressIndicatorFrame = rect; 

그리고

//// Abstracted Attributes 
CGRect progressTrackActiveRect = CGRectMake(CGRectGetMinX(activeProgressFrame) + 4, CGRectGetMinY(activeProgressFrame) + 5, CGRectGetWidth(activeProgressFrame) - 8, 10); 

는 또한이

//// Abstracted Attributes 
CGRect progressTrackActiveRect = CGRectMake(CGRectGetMinX(activeProgressFrame) + 4, CGRectGetMinY(activeProgressFrame) + 5, (CGRectGetWidth(activeProgressFrame) - 8) * self.progress, 10); 

과 같아야이 줄을 같이해야 7, 당신은 t를 필요로 할 것입니다. o UIProgressView 서브 클래스에서 모든 서브 뷰를 제거하십시오. 나는 IB를 사용하고, 그래서 내 initWithCoder : 메소드는 다음과 같습니다

-(id)initWithCoder:(NSCoder *)aDecoder { 
    self = [super initWithCoder:aDecoder]; 
    if(self) { 
     NSArray *subViews = self.subviews; 
     for(UIView *view in subViews) { 
      [view removeFromSuperview]; 
     } 
    } 
    return self; 
} 

그렇지 않다면, 당신은 사용자 정의 진행률 표시 줄에 중첩 기본 찾고 진행률 표시 줄을해야합니다.