Note that there are some explanatory texts on larger screens.

plurals
  1. PODrawing linear gradient in a rect works on iOS 5.x but not 4.x
    primarykey
    data
    text
    <p>I have some code that I use to fill a view with a linear gradient, I've refactored this into a helper method. This draws fine on iOS 5.x but when I tried running on 4.3.5 I don't get anything. I've checked all the CG calls and they all are supported on 4.0 or older, it look so simplistic I can't see why it doesn't work on 4.x.</p> <pre><code>- (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); CGColorRef startColor = [UIColor lightGrayColor].CGColor; CGColorRef endColor = [UIColor blackColor].CGColor; CGRect paperRect = self.frame; [GraphicsHelpers drawLinearGradientWithContext:context inRect:paperRect startColor:startColor endColor:endColor]; } </code></pre> <p>Here is that method</p> <pre><code>+ (void)drawLinearGradientWithContext:(CGContextRef)context inRect:(CGRect)rect startColor:(CGColorRef)startColor endColor:(CGColorRef)endColor { CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); CGFloat locations[] = { 0.0, 1.0 }; NSArray *colors = [NSArray arrayWithObjects:(__bridge id)startColor, (__bridge id)endColor, nil]; CGGradientRef gradient = CGGradientCreateWithColors(colorSpace, (__bridge CFArrayRef) colors, locations); CGPoint startPoint = CGPointMake(CGRectGetMidX(rect), CGRectGetMinY(rect)); CGPoint endPoint = CGPointMake(CGRectGetMidX(rect), CGRectGetMaxY(rect)); CGContextSaveGState(context); CGContextAddRect(context, rect); CGContextClip(context); CGContextDrawLinearGradient(context, gradient, startPoint, endPoint, 0); CGContextRestoreGState(context); CGGradientRelease(gradient); CGColorSpaceRelease(colorSpace); </code></pre> <p>}</p> <p>I found most of this code <a href="http://www.raywenderlich.com/2033/core-graphics-101-lines-rectangles-and-gradients" rel="nofollow">here</a> and was working great until I started testing on older OS versions as I'm close to release.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload