Files
RubyMotion/sample/hello/app/hello_view.rb
Laurent Sansonetti 6cf7150783 clean up the samples
2012-02-28 14:41:27 +01:00

34 lines
810 B
Ruby

class HelloView < UIView
def drawRect(rect)
if @moved
bgcolor = begin
red, green, blue = rand(100), rand(100), rand(100)
UIColor.colorWithRed(red/100.0, green:green/100.0, blue:blue/100.0, alpha:1.0)
end
text = "ZOMG!"
else
bgcolor = UIColor.blackColor
text = @touches ? "Touched #{@touches} times!" : "Hello RubyMotion!"
end
bgcolor.set
UIBezierPath.bezierPathWithRect(frame).fill
font = UIFont.systemFontOfSize(24)
UIColor.whiteColor.set
text.drawAtPoint(CGPoint.new(10, 20), withFont:font)
end
def touchesMoved(touches, withEvent:event)
@moved = true
setNeedsDisplay
end
def touchesEnded(touches, withEvent:event)
@moved = false
@touches ||= 0
@touches += 1
setNeedsDisplay
end
end