Skip to content

Instantly share code, notes, and snippets.

@GantMan
Last active December 18, 2015 22:39
Show Gist options
  • Save GantMan/5855737 to your computer and use it in GitHub Desktop.
Save GantMan/5855737 to your computer and use it in GitHub Desktop.
Code Gists from the Book
class AppDelegate
def application(application, didFinishLaunchingWithOptions:launchOptions)
true
end
end
class AppDelegate
def application(application, didFinishLaunchingWithOptions:launchOptions)
@window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
true
end
end
class AppDelegate
def application(application, didFinishLaunchingWithOptions:launchOptions)
@window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
@window.makeKeyAndVisible
true
end
end
describe "Application 'HelloWorld'" do
before do
@app = UIApplication.sharedApplication
@window = @app.windows[0]
end
it "has one window" do
@app.windows.size.should == 1
end
it "has a rootViewController" do
@window.rootViewController.should.not == nil
end
it "uses HelloWorldController as the rootViewController" do
@window.rootViewController.class.should.equal HelloWorldController
end
end
class HelloWorldController < UIViewController
end
class AppDelegate
def application(application, didFinishLaunchingWithOptions:launchOptions)
@window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
@window.rootViewController = HelloWorldController.new
@window.makeKeyAndVisible
true
end
end
class HelloWorldController < UIViewController
def viewDidLoad
puts "Hello World"
end
end
describe "HelloWorldController" do
tests HelloWorldController
it "has a UILabel with text correct text" do
label = controller.instance_variable_get("@label")
# check text
label.text.should.equal "Hello World"
# make sure it is added on the view
controller.view.subviews.should.include? label
end
end
class HelloWorldController < UIViewController
def viewDidLoad
p "Hello World"
view.backgroundColor = UIColor.whiteColor
@label = UILabel.new
@label.text = "Hello World"
@label.frame = [[50, 50], [150, 50]]
view.addSubview(@label)
end
end
class HelloWorldController < UIViewController
def viewDidLoad
p "Hello World"
view.backgroundColor = UIColor.whiteColor
center_x = view.frame.size.width / 2
center_y = view.frame.size.height / 2
@label = UILabel.new
@label.text = "Hello World"
@label.sizeToFit
@label.center = [center_x, center_y]
view.addSubview(@label)
end
end
# -*- coding: utf-8 -*-
$:.unshift("/Library/RubyMotion/lib")
require 'motion/project/template/ios'
Motion::Project::App.setup do |app|
# Use `rake config' to see complete project settings.
app.name = 'HelloWorld'
app.device_family = [:iphone, :ipad]
end
# A sample Gemfile
source "https://rubygems.org"
gem "awesome_print_motion"
gem "teacup"
gem "sugarcube"
gem "sweettea"
# -*- coding: utf-8 -*-
$:.unshift("/Library/RubyMotion/lib")
require 'motion/project/template/ios'
require 'bundler'
Bundler.require
Motion::Project::App.setup do |app|
# Use `rake config' to see complete project settings.
app.name = 'HelloWorld'
app.device_family = [:iphone, :ipad]
end
class HelloWorldController < UIViewController
def viewDidLoad
p "Hello World"
# Made better with Sugarcube
# @colors = [UIColor.whiteColor, UIColor.redColor]
@colors = [:white.uicolor, :red.uicolor, :yellow.uicolor, :blue.uicolor]
1.second.every do
view.backgroundColor = @colors.sample
end
# see the magic of Awesome Print!
ap @colors
center_x = view.frame.size.width / 2
center_y = view.frame.size.height / 2
@label = UILabel.new
@label.text = "Hello World"
@label.sizeToFit
@label.center = [center_x, center_y]
view.addSubview(@label)
end
end
class HelloWorldController < UIViewController
stylesheet :main
layout :main do
@label = subview(UILabel, :hello_label)
end
def layoutDidLoad
p "Hello World"
# Made better with Sugarcube
# @colors = [UIColor.whiteColor, UIColor.redColor]
@colors = [:white.uicolor, :red.uicolor, :yellow.uicolor, :blue.uicolor]
1.second.every do
view.backgroundColor = @colors.sample
end
# see the magic of Awesome Print!
ap @colors
end
end
Teacup::Stylesheet.new :main do
style :hello_label,
text: "Hello World",
width: 89,
height: 21,
center: ['50%', '50%'],
backgroundColor: :clear
end
Teacup::Stylesheet.new :main do
style :hello_label,
text: "Hello World",
sizeToFit: true,
center: ['50%', '50%'],
backgroundColor: :clear
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment