Created
June 30, 2013 18:07
-
-
Save anonymous/5896208 to your computer and use it in GitHub Desktop.
Example of using Teacup styles and stylesheets inside a UIView Gems in use: gem "teacup"
gem "sugarcube"
gem "sweettea"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Teacup::Stylesheet.new :root_style do | |
style :label, | |
text: "Label", | |
backgroundColor: :gray, | |
font: :bold.uifont(15), | |
textColor: :white, | |
shadowColor: :black, | |
textAlignment: :right, | |
layer: { | |
transform: identity, | |
shadowRadius: 20, | |
shadowOpacity: 0.5, | |
masksToBounds: false | |
}, | |
frame: [[100,0], [100,100]], | |
constraints: [ | |
constrain_top(30), | |
constrain(:right).equals(:superview, :center_x), | |
constrain(:width).equals(:superview, :width).times(1.5) | |
] | |
end | |
class RootView < UIView | |
include Teacup::Layout | |
stylesheet :root_style | |
attr_accessor :greeting | |
def initialize | |
ap "RootView initialize" | |
end | |
def initWithFrame(frame) | |
ap "RootView.initWithFrame called" | |
@greeting = "Hello World" | |
super.tap do | |
self.style(backgroundColor: :white) | |
@label_styled = layout(UILabel, :label) | |
# Creating a UILabel without a stylesheet reference | |
@label = UILabel.new | |
@label.style( | |
text: @greeting, | |
backgroundColor: :blue, | |
x: 0.0, y: 0.0, | |
width: 100.0, height: 100.0 | |
) | |
@button = UIButton.rounded_rect | |
@button.style(title: "Press me", | |
x: 100, y: 200, | |
width: 150, height: 20) | |
@button.addTarget(self, action:'button_touched', forControlEvents:UIControlEventTouchUpInside) | |
addSubview @label | |
addSubview @label_styled | |
addSubview @button | |
end | |
end | |
def button_touched | |
ap "RootView Button Touched" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment