Why is custom drawRect not shown in 6.1 simulator?

Inside the UICollectionViewCell there is a subclass of UIView ( ThumbView ). The following code works fine in the iOS 7 simulator:

 - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { static NSString *identifier = @"Cell"; UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath]; ThumbView *thumbView = (ThumbView *)[cell viewWithTag:1]; [thumbView setNeedsDisplay]; return cell; } 

enter image description here

However, in the iOS version 6 of the simulator:

Grids resolved:

enter image description here

I put an NSLog in a drawRect ThumbView to make sure drawRect is called.

What's wrong?

  • Xcode Version 5.0 (5A1412)
  • iOS Simulator Version 7.0 (463.9.4)

UPDATE (drawing code):

 - (void)drawRect:(CGRect)rect { NSLog(@"%s", __func__); [self drawGrid:rect]; } - (void)drawGrid:(CGRect)rect { CGFloat margin = self.margin; CGFloat lineWidth = 2.0; CGContextRef context = UIGraphicsGetCurrentContext(); CGRect gridRect = CGRectInset(rect, margin, margin); for (NSInteger i = 1; i < 9; i++) { CGFloat h = gridRect.size.height / 9; CGFloat y = i * h; CGContextMoveToPoint(context, margin, y+margin); CGContextAddLineToPoint(context, gridRect.size.width+margin, y+margin); CGContextSetLineWidth(context, lineWidth/4.0); if (i == 3 || i == 6) { CGContextSetStrokeColorWithColor(context, UIColor.darkGrayColor.CGColor); } else { CGContextSetStrokeColorWithColor(context, UIColor.lightGrayColor.CGColor); } CGContextStrokePath(context); } for (NSInteger i = 1; i < 9; i++) { CGFloat w = gridRect.size.width / 9; CGFloat x = i * w; CGContextMoveToPoint(context, x+margin, margin); CGContextAddLineToPoint(context, x+margin, gridRect.size.height+margin); CGContextSetLineWidth(context, lineWidth/4.0); if (i == 3 || i == 6) { CGContextSetStrokeColorWithColor(context, UIColor.darkGrayColor.CGColor); } else { CGContextSetStrokeColorWithColor(context, UIColor.lightGrayColor.CGColor); } CGContextStrokePath(context); } CGFloat frameWidth = lineWidth * 2.0; CGRect frameRect = CGRectInset(rect, 0.0, 0.0); if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) frameWidth = lineWidth * 2.0; CGContextSetLineWidth(context, frameWidth); CGContextSetStrokeColorWithColor(context, UIColor.darkGrayColor.CGColor); CGContextStrokeRect(context, frameRect); } 
+7
ios ios-simulator drawrect
source share
2 answers

It's hard to say without looking at the code. I saw such things when I run the code on the retina against a non-retina simulator and incorrectly take into account the difference in scale.

+2
source share

Have you verified that you are not drawing white lines on a white background in iOS6? (if you use tintColor in iOS7, for example ...)

+1
source share

All Articles