Skip to content

Instantly share code, notes, and snippets.

@cutemachine
Created May 10, 2012 14:58
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cutemachine/2653701 to your computer and use it in GitHub Desktop.
Save cutemachine/2653701 to your computer and use it in GitHub Desktop.
GradientView with RubyMotion
class GradientView < UIView
def initWithFrame(frame)
if super
rgb = CGColorSpaceCreateDeviceRGB()
ptr = Pointer.new(:float, 8)
ptr[0] = 1.0
ptr[1] = 0.0
ptr[2] = 0.0
ptr[3] = 1.0
ptr[4] = 0.0
ptr[5] = 0.0
ptr[6] = 0.0
ptr[7] = 1.0
@gradient = CGGradientCreateWithColorComponents(rgb, ptr, nil, 2)
CGColorSpaceRelease(rgb)
end
self
end
def drawRect(rect)
context = UIGraphicsGetCurrentContext()
start = rect.origin
start.y = 0;
end_point = CGPointMake(rect.origin.x, 480.0)
CGContextDrawLinearGradient(context, @gradient, start, end_point, KCGGradientDrawsBeforeStartLocation | KCGGradientDrawsAfterEndLocation)
super
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment