Skip to content

Instantly share code, notes, and snippets.

@paulsturgess
Last active December 15, 2015 11:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulsturgess/5256999 to your computer and use it in GitHub Desktop.
Save paulsturgess/5256999 to your computer and use it in GitHub Desktop.
Idea for a standard approach to setting up the basics of a RubyMotion app
class AppController < UIViewController
def loadView
self.view = AppView.alloc.init
end
def viewDidLoad
super
view.viewDidLoad
end
end
class AppDelegate
def application(application, didFinishLaunchingWithOptions:launchOptions)
@window = AppWindow.alloc.initWithFrame
true
end
end
class AppView < UIView
def viewDidLoad
self.addSubview(label)
# ...
end
def label
@label ||= CustomLabel.alloc.initWithFrame
end
end
class AppWindow < UIWindow
def initWithFrame
super(UIScreen.mainScreen.bounds)
self.send(:initialize)
self
end
def initialize
self.makeKeyAndVisible
self.rootViewController = appController
end
def appController
@appController ||= AppController.alloc.init
end
end
class CustomLabel < UILabel
def initWithFrame
super([[10,60], [300,80]])
self.send(:initialize)
self
end
def initialize
self.backgroundColor = UIColor.lightGrayColor
self.text = "Some text..."
# ...
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment