Adds methods to apply shadows to UIViews

This commit is contained in:
Mark Rickert
2015-01-24 12:35:38 -05:00
parent d1a7618da4
commit 7e0ffd73ff
2 changed files with 34 additions and 0 deletions

View File

@@ -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

View File

@@ -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