bigsml / adwhirl

Automatically exported from code.google.com/p/adwhirl
0 stars 1 forks source link

In House Ad background color returned by adWhirlAdBackgroundColor not rendered properly (iphone) #182

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1.  Use adwhirl sample project (AdWhirlSDK2_Sample) and change 
SimpleViewController.m method - (UIColor *)adWhirlAdBackgroundColor to return 
something like black color:

- (UIColor *)adWhirlAdBackgroundColor {
  return [UIColor blackColor];
}

2.  Compile and run, I tried both iphone4 ios4.0 device and 4.2 simulator

What is the expected output? What do you see instead?
  House ad background is flat white, instead of supposed gradient.

What version of the product are you using? On what operating system?
  Using adwhirlsdk 2.6.3, on ios4.0.3 device or 4.2 simulator

Please provide any additional information below.
  I had to change the "AdWhirlCustomAdView.m" drawrect method to make it display correctly.

Here's the code:

- (void)drawRect:(CGRect)rect {

  CGContextRef ctx = UIGraphicsGetCurrentContext();
  if (adType == AWCustomAdTypeText) {

    // draw background
    // begin modification by sean

    CGFloat locations[kNumBgColors] = {0.0, 0.7, 1.0};
    CGColorRef colorArray[kNumBgColors] =
      {[backgroundColor colorWithAlphaComponent:0.6].CGColor,
       backgroundColor.CGColor,
       backgroundColor.CGColor};
    CFArrayRef colors = CFArrayCreate(kCFAllocatorDefault,
                                      (const void **)colorArray,
                                      kNumBgColors,
                                      &kCFTypeArrayCallBacks);
    CGGradientRef gradient = CGGradientCreateWithColors(NULL, colors, locations);
    CFRelease(colors);
    CGContextSetFillColorWithColor(ctx, [UIColor whiteColor].CGColor);
    CGContextFillRect(ctx, CGRectMake(0, 0, CGRectGetWidth(self.bounds), CGRectGetHeight(self.bounds)));
    CGPoint midY = CGPointMake(0.0, CGRectGetHeight(self.bounds)/2);
    CGPoint lowY = CGPointMake(0.0, CGRectGetHeight(self.bounds));
    CGContextDrawLinearGradient(ctx, gradient, CGPointZero, midY, 0);
    CGContextDrawLinearGradient(ctx, gradient, lowY, midY, 0);
    CGGradientRelease(gradient);

    //end modification by sean

    // draw image and chamfer
    CGFloat imageTop = (CGRectGetHeight(self.bounds) - kImageDim)/2.0;
    CGPoint tl = CGPointMake(kImageLeft+kCornerRadius, imageTop+kCornerRadius);
    CGPoint tr = CGPointMake(kImageLeft+kImageDim-kCornerRadius, imageTop+kCornerRadius);
    CGPoint br = CGPointMake(kImageLeft+kImageDim-kCornerRadius, imageTop+kImageDim-kCornerRadius);
    CGPoint bl = CGPointMake(kImageLeft+kCornerRadius, imageTop+kImageDim-kCornerRadius);
    CGContextSaveGState(ctx);
    CGContextMoveToPoint(ctx, kImageLeft, imageTop+kCornerRadius);
    CGContextAddArc(ctx, tl.x, tl.y, kCornerRadius, M_PI, 3*M_PI/2, 0);
    CGContextAddArc(ctx, tr.x, tr.y, kCornerRadius, 3*M_PI/2, 0, 0);
    CGContextAddArc(ctx, br.x, br.y, kCornerRadius, 0, M_PI/2, 0);
    CGContextAddArc(ctx, bl.x, bl.y, kCornerRadius, M_PI/2, M_PI, 0);
    CGContextClosePath(ctx);
    CGContextClip(ctx);
    [image drawAtPoint:CGPointMake(kImageLeft, imageTop)];
    CGContextSetLineWidth(ctx, 0.5);
    CGContextMoveToPoint(ctx, kImageLeft, imageTop+kImageDim-kCornerRadius);
    CGContextSetStrokeColorWithColor(ctx, kChamferDark);
    CGContextAddArc(ctx, tl.x, tl.y, kCornerRadius, M_PI, 5*M_PI/4, 0);
    CGContextStrokePath(ctx);
    CGContextSetStrokeColorWithColor(ctx, kChamferLight);
    CGContextAddArc(ctx, tl.x, tl.y, kCornerRadius, 5*M_PI/4, 3*M_PI/2, 0);
    CGContextAddArc(ctx, tr.x, tr.y, kCornerRadius, 3*M_PI/2, 0, 0);
    CGContextAddArc(ctx, br.x, br.y, kCornerRadius, 0, M_PI/4, 0);
    CGContextStrokePath(ctx);
    CGContextSetStrokeColorWithColor(ctx, kChamferDark);
    CGContextAddArc(ctx, br.x, br.y, kCornerRadius, M_PI/4, M_PI/2, 0);
    CGContextAddArc(ctx, bl.x, bl.y, kCornerRadius, M_PI/2, M_PI, 0);
    CGContextStrokePath(ctx);
    CGContextRestoreGState(ctx);

  } // text ad
  else if (adType == AWCustomAdTypeBanner) {
    // draw image, place image in center of frame
    [image drawAtPoint:CGPointMake((self.frame.size.width-image.size.width)/2,
                                   (self.frame.size.height-image.size.height)/2)];
  } // banner ad
}

Original issue reported on code.google.com by surl...@gmail.com on 4 Mar 2011 at 11:28

GoogleCodeExporter commented 8 years ago

Original comment by wesgood...@google.com on 30 Nov 2011 at 9:24