mirror of
https://github.com/zhigang1992/RubyMotion.git
synced 2026-04-14 23:28:10 +08:00
50 lines
1.2 KiB
Ruby
50 lines
1.2 KiB
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
|
|
|
|
class HelloViewController < UIViewController
|
|
def loadView
|
|
self.view = HelloView.alloc.init
|
|
end
|
|
end
|
|
|
|
class AppDelegate
|
|
def application(application, didFinishLaunchingWithOptions:launchOptions)
|
|
@window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
|
|
@window.rootViewController = HelloViewController.alloc.init
|
|
@window.rootViewController.wantsFullScreenLayout = true
|
|
@window.makeKeyAndVisible
|
|
return true
|
|
end
|
|
end
|