From 7e0ffd73ffb05be989fa6aa51e832b7752b6e3db Mon Sep 17 00:00:00 2001 From: Mark Rickert Date: Sat, 24 Jan 2015 12:35:38 -0500 Subject: [PATCH] Adds methods to apply shadows to UIViews --- .../stylers/ui_view_styler.rb | 19 +++++++++++++++++++ spec/stylers/_ui_view_styler.rb | 15 +++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/motion/ruby_motion_query/stylers/ui_view_styler.rb b/motion/ruby_motion_query/stylers/ui_view_styler.rb index 8874e78..437b2d0 100644 --- a/motion/ruby_motion_query/stylers/ui_view_styler.rb +++ b/motion/ruby_motion_query/stylers/ui_view_styler.rb @@ -316,7 +316,26 @@ module RubyMotionQuery def alpha ; view.alpha ; end def alpha=(v) ; view.alpha = v ; end + def shadow_color=(c) + c = c.CGColor if c.kind_of?(UIColor) + @view.layer.shadowColor = c + end + def shadow_color ; @view.layer.shadowColor ; end + def shadow_offset=(offset) + @view.layer.shadowOffset = offset + end + def shadow_offset ; @view.layer.shadowOffset ; end + + def shadow_opacity=(opacity) + @view.layer.shadowOpacity = opacity + end + def shadow_opacity ; @view.layer.shadowOpacity ; end + + def shadow_path=(path) + @view.layer.shadowPath = path + end + def shadow_path ; @view.layer.shadowPath ; end # @deprecated - use frame hashs diff --git a/spec/stylers/_ui_view_styler.rb b/spec/stylers/_ui_view_styler.rb index 164942b..253d140 100644 --- a/spec/stylers/_ui_view_styler.rb +++ b/spec/stylers/_ui_view_styler.rb @@ -50,6 +50,12 @@ class SyleSheetForUIViewStylerTests < RubyMotionQuery::Stylesheet st.background_color = color.red st.tint_color = color.blue st.corner_radius = 5 + + # Shadows + st.shadow_color = color.gray + st.shadow_offset = CGSizeMake(0, 5) + st.shadow_opacity = 0.5 + st.shadow_path = UIBezierPath.bezierPathWithRect(st.view.bounds).CGPath end end @@ -319,4 +325,13 @@ describe 'ui_view_styler' do @value.should.be.false end + + it "should set shadow values" do + view = @vc.rmq.append(@view_klass, :ui_view_kitchen_sink).get + + view.layer.shadowColor.should == rmq.color.gray.CGColor + view.layer.shadowOffset.should == CGSizeMake(0.0, 5.0) + view.layer.shadowOpacity.should == 0.5 + view.layer.shadowPath.should == UIBezierPath.bezierPathWithRect(view.bounds).CGPath + end end