0.0
No commit activity in last 3 years
No release in over 3 years
Plastic Cup is a simplified version of Teacup, aiming at memory leak prevention. It allow assigning properties to object by hash and define stylesheets, in a dummy way.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies
 Project Readme

Plastic Cup

Plastic Cup is a simplified version of Teacup, aiming at memory leak prevention. It allow assigning properties to object by hash and define stylesheets, in a dummy way.

Usage

Style by Hash

@button = PlasticCup::Base.style(UIButton.new, {title: 'Red', backgroundColor: UIColor.redColor})

Style by Stylesheet

PlasticCup::Base.add_style_sheet(:red_button, {
  title: 'Red',
  backgroundColor: UIColor.redColor
})
@button = PlasticCup::Base.style(UIButton.new, :red_button)
@button2 = PlasticCup::Base.style(UIButton.new, :red_button, title: 'Another Red')

Style with extend Stylesheet

PlasticCup::Base.add_style_sheet(:round_label, {
  layer: {
    cornerRadius: 8
  }
})
PlasticCup::Base.add_style_sheet(:green_label, {
  extends: :round_label,
  backgroundColor: UIColor.greenColor
}
@label = PlasticCup::Base.style(UILabel.new, :green_label)

Support different iOS versions

PlasticCup::Base.add_style_sheet(:bg_view, {
  frame: CGRectMake(0, 0, 320, 200)
}, :all)

PlasticCup::Base.add_style_sheet(:bg_view, {
  frame: CGRectMake(0, 20, 320, 200)
}, :ios7)
# supported symbols: :all, :ios4, :ios5, :ios6, :ios7, :ios8
# default is :all

If you define stylesheet outside methods, some values (e.g. UIFont) need to be in Proc form:

PlasticCup::Base.add_style_sheet(:login_title, {
    text: 'Login',
    font: lambda {UIFont.systemFontOfSize(28)}
})

Important: Don't add handler inside any instance method

Will leak:

def viewDidLoad
  super

  PlasticCup::Base.handler UIButton, :highlighted_image do |target, image|
    target.setImage(image, forState: UIControlStateHighlighted)
  end
end

Will not leak:

PlasticCup::Base.handler UIButton, :highlighted_image do |target, image|
  target.setImage(image, forState: UIControlStateHighlighted)
end

def viewDidLoad
  super
end