yannickl / YLProgressBar

UIProgressView replacement with an highly and fully customizable animated progress bar in pure Core Graphics
http://yannickloriot.com/library/ios/ylprogressbar/
MIT License
1.28k stars 186 forks source link

YLProgressBar found a garbage value in line 606 #49

Closed hccgk closed 7 years ago

hccgk commented 7 years ago

use xcode analyze will show this problem

hccgk commented 7 years ago
- (void)drawText:(CGContextRef)context withRect:(CGRect)rect
{
  if (_indicatorTextLabel == nil)
  {
    return;
  }

  CGRect innerRect          = CGRectInset(rect, 4, 2);
  _indicatorTextLabel.frame = innerRect;

  NSString *indicatorText = _indicatorTextLabel.text;
  BOOL hasText            = (_indicatorTextLabel.text != nil);

  if (!hasText)
  {
    indicatorText = [NSString stringWithFormat:@"%.0f%%", (self.progress * 100)];
  }

    CGRect textRect;
    if ([indicatorText respondsToSelector:@selector(boundingRectWithSize:options:attributes:context:)])
    {
        textRect = [indicatorText boundingRectWithSize:CGRectInset(innerRect, 20, 0).size
                                               options:NSStringDrawingUsesLineFragmentOrigin
                                            attributes:@{ NSFontAttributeName: _indicatorTextLabel.font }
                                               context:nil];
    }
        **if (innerRect.size.width < textRect.size.width || innerRect.size.height + 4 < textRect.size.height)**
        {
            return;
        }
yannickl commented 7 years ago

Thank you for the hint! And sorry for the late.