Why custom drawRect is not shown in 6.1 simulator?
Asked Answered
E

2

7

There is a UIView subclass (ThumbView) inside a UICollectionViewCell. The following code works great in 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 6 version of the simulator:

The grids are all gone:

enter image description here

I have put a NSLog in the drawRect of the ThumbView to make sure drawRect is called.

What is wrong?

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

UPDATE (the 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);
}
Ellamaeellan answered 17/9, 2013 at 6:28 Comment(6)
Is there a typo in your question because method name is drawRect:?Radicalism
typo is only in the question, fixed. thanks.Ellamaeellan
Despite iOS 7's release being just around the corner, it is still under NDA so you are not likely to get a good answer until then.Lieu
How are you adding ThumbView as a subview of the UICollectionViewCell?Pich
Can you post some of your drawing code so that we can have some material to look over and see where the problem lies?Junco
@ChristianDiLorenzo drawing code is added in questionEllamaeellan
L
2

Without seeing the code it is hard to say. I have seen things like this when I run code on a retina versus non-retina simulator and don't properly account for scale difference.

Leonardoleoncavallo answered 30/9, 2013 at 22:55 Comment(0)
V
1

Have you checked that you're not drawing white lines on a white background in iOS6? (if you're using tintColor in iOS7 for example...)

Voroshilovgrad answered 27/9, 2013 at 17:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.