Created
May 10, 2012 14:58
-
-
Save cutemachine/2653701 to your computer and use it in GitHub Desktop.
GradientView with RubyMotion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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