Sunday, October 11, 2009

iPhone dev Stupidity 74: UIScrollView beyond bounds gradient?

From here:


// Setup top most gradient parameters and clipping mask.


CGPoint startPoint = CGPointMake(rect.origin.x, rect.origin.y);


CGPoint endPoint = CGPointMake(0.0, shadowHeight_);


CGRect clipRect = CGRectMake(rect.origin.x, rect.origin.y, rect.size.width, shadowHeight_);



// Draw top most gradient within clipped rect. Look at Quartz Demo for details.


CGContextSaveGState(context);


CGContextClipToRect(context, clipRect);


CGContextDrawLinearGradient(context, gradient, startPoint, endPoint, 0);


CGContextRestoreGState(context);



and to setup the gradient:

CGColorSpaceRef rgb = CGColorSpaceCreateDeviceRGB();



        CGFloat colors[] = {


            //0.0, 0.0, 0.0, 0.5,


            //1.0, 1.0, 1.0, 0.0


65.0/256, 81.0/256, 81.0/256, 1.0,


0.0, 0.0, 0.0, 1.0,


        };


        


        gradient = CGGradientCreateWithColorComponents(rgb, colors, NULL, 2);


        


        CGColorSpaceRelease(rgb);


No comments: