Skip to content

Instantly share code, notes, and snippets.

@Cosmo
Created June 3, 2012 16:34
Show Gist options
  • Save Cosmo/2864098 to your computer and use it in GitHub Desktop.
Save Cosmo/2864098 to your computer and use it in GitHub Desktop.
css dsl for rubymotion
# Inline styles
@calculate_button = UIButton.named(I18n.t(:calculate_button)).style(color: 0xFFFFFF, align: :center, vertical_align: :center, top: 10, left: 30, width: 120, height: 40)
# External styles
# /app/stylesheets/application.rb
class ApplicationStylesheet < Stylesheets::Base
# Stylesheets for UI-Elements
# usage: @element.outfit(:awesome_default)
outfit :description_label do |o|
o.color 0xFFFFFF
o.align :center
o.width 400
o.height 300
o.top 40
o.left 60
end
outfit :awesome_default do |o|
o.color 0xFFFFFF
o.align :center
o.top 40
o.left 60
o.background_color 0x000000
o.background_image "default_background.png"
o.background_size :cover
# Set "label.png" as background image only if it's an UITextField-Element
o.context UITextfield do |c|
c.background_image "textfield.png"
end
# Set "label.png" as background image only
# if it's an UILabel-Element and device orientation is landscape
o.context UILabel, :landscape do |c|
c.background_image "label_landscape.png"
end
# Set "label.png" as background image only
# if it's an UILabel-Element and device orientation is portrait
o.context UILabel, :portrait do |c|
c.background_image "label_portrait.png"
end
end
end
# /app/stylesheets/application.pad.rb
# Additional outfit for iPad devices
class Application < Stylesheets::Pad
outfit :awesome_default do |o|
o.width 400
o.height 300
end
end
# /app/stylesheets/application.phone.rb
# Additional outfit for iPhone and iPod touch devices
class Application < Stylesheets::Phone
outfit :awesome_default do |o|
o.width 200
o.height 100
end
end
# /app/somewhere_else.rb
@calculate_button = button.named("calculate").outfit(:awesome_default)
@calculate_button.on(:press) do |b|
calculate
end
@calculate_button.on(:swipe_left) do |b|
calculate_with_awesome_effect
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment