1

I'm working with autolayout and I have a RoundView class (subview of UIButton) which drawRect method is:

- (void)drawRect:(CGRect)rect
{
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGFloat lineWidth = 0.0;
    CGContextSetLineWidth(context, lineWidth);
    CGContextSetFillColorWithColor(context, _currentBackgroundColor.CGColor);
    CGContextAddEllipseInRect(context, self.bounds);
    CGContextFillPath(context);

}

Then I add it to self (a UIView), set its width and height using autolayout. Everything looks great. But when I change its size constraints (to have a bigger view), and call

[self layoutIfNeeded];

in an animation block, the circle pixels look bigger and ugly.

Do I do this the correct way ?

correct incorrect

The Windwaker
  • 1,054
  • 12
  • 24

2 Answers2

11

I just got it from this post !

The problem was that the os wasn't calling drawRect at each animation step. To force it, in RoundView's init:

self.contentMode = UIViewContentModeRedraw;
Community
  • 1
  • 1
The Windwaker
  • 1,054
  • 12
  • 24
0

You need to take the content scale into account for the retina displays [UIDevice mainScreen].scale. See answers to this (question)[CGContext and retina display

Community
  • 1
  • 1
Lev Landau
  • 788
  • 3
  • 16