Skip to content

Instantly share code, notes, and snippets.

@makevoid
Last active October 4, 2015 06:48
Show Gist options
  • Select an option

  • Save makevoid/2596291 to your computer and use it in GitHub Desktop.

Select an option

Save makevoid/2596291 to your computer and use it in GitHub Desktop.
Hello Button in RubyMotion (a bit more than hello world)
# Hello ButtonView (world)
class AppDelegate
def application(application, didFinishLaunchingWithOptions:launchOptions)
@window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
@window.rootViewController = ButtonViewController.alloc.init
@window.makeKeyAndVisible
return true
end
end
class ButtonView < UIView
def drawRect(rect)
# draw text
font = UIFont.systemFontOfSize(24)
UIColor.whiteColor.set
text = "Hello RubyMotion!"
text.drawAtPoint(CGPoint.new(10, 20), withFont:font)
# draw button
button = UIButton.buttonWithType UIButtonTypeRoundedRect
button.addTarget(self, action:"bam", forControlEvents: UIControlEventTouchDown)
button.setTitle("Execute bam method", forState: UIControlStateNormal)
button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0)
self.addSubview button
end
def bam
puts "baaaam!!!!"
end
end
class ButtonViewController < UIViewController
def loadView
self.view = ButtonView.alloc.init
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment