Added button stylers from sxross (https://github.com/sxross)

This commit is contained in:
Todd Werth
2014-03-14 09:55:55 -07:00
parent e481f5a68d
commit 3209e420ce
2 changed files with 80 additions and 0 deletions

View File

@@ -45,6 +45,34 @@ module RubyMotionQuery
@view.setBackgroundImage value, forState: UIControlStateHighlighted
end
def border_color=(value)
if value.is_a?(UICachedDeviceRGBColor)
@view.layer.setBorderColor(value.CGColor)
else
@view.layer.setBorderColor value
end
end
def border_color
@view.layer.borderColor
end
def corner_radius=(value = 2)
@view.layer.cornerRadius = value
end
def corner_radius
@view.layer.cornerRadius
end
def border_width=(value)
@view.layer.borderWidth = value
end
def border_width
@view.layer.borderWidth
end
end
end
end

View File

@@ -26,5 +26,57 @@ describe 'stylers/ui_button' do
# TODO
1.should == 1
end
end
describe "bordered button extensions" do
before { @view = @vc.rmq.append(@view_klass, :ui_button_kitchen_sink) }
describe "border width" do
before{ @view.style{|st| st.border_width = 2} }
it 'should be able to add a border to a button' do
@view.get.layer.borderWidth.should == 2
end
it "can get a border width for a button" do
bw = nil
@view.style{|st| bw = st.border_width}
bw.should == 2
end
end
describe "corner radius" do
before{ @view.style{|st| st.corner_radius = 10} }
it "sets the corner radius" { @view.get.layer.cornerRadius.should == 10 }
it "gets the corner radius" do
cr = nil
@view.style{|st| cr = st.corner_radius}
cr.should == 10
end
end
describe "border colors" do
before{ @view.style{|st| st.border_color = rmq.color.blue} }
it "sets the correct number of color components" do
CGColorGetNumberOfComponents(@view.get.layer.borderColor).should >= 4
end
it "sets the right colors" do
color = nil
@view.style{|st| color = st.border_color}
components = CGColorGetComponents(color)
# R=0, G=0, B=1 A=1
components[0].to_i.should == 0
components[1].to_i.should == 0
components[2].to_i.should == 1
components[3].to_i.should == 1
end
end
end
end