mirror of
https://github.com/zhigang1992/rmq.git
synced 2026-01-12 17:52:17 +08:00
Merge pull request #187 from squidpunch/background-gradient
Add the ability to make a background gradient on a view
This commit is contained in:
@@ -194,8 +194,11 @@ class MainControllerStylesheet < ApplicationStylesheet
|
||||
end
|
||||
|
||||
def validation_section(st)
|
||||
st.background_color = color.yellow
|
||||
st.frame = 'a7:e10'
|
||||
st.background_gradient = {
|
||||
colors: [color.yellow, color.black],
|
||||
locations: [0.0, 1.0]
|
||||
}
|
||||
end
|
||||
|
||||
def validation_title(st)
|
||||
|
||||
@@ -494,6 +494,19 @@ module RubyMotionQuery
|
||||
end
|
||||
end
|
||||
|
||||
#param is a hash of locations and colors: { locations: [], colors: [] }
|
||||
def background_gradient=(options)
|
||||
colors = options.fetch(:colors).collect { |c| c.CGColor }
|
||||
locations = options.fetch(:locations)
|
||||
|
||||
CAGradientLayer.alloc.init.tap do |layer|
|
||||
layer.colors = colors
|
||||
layer.locations = locations
|
||||
view.layer.insertSublayer(layer, atIndex: 0)
|
||||
view.layer.sublayers[0].frame = view.bounds
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def is_color(value)
|
||||
|
||||
@@ -334,4 +334,33 @@ describe 'ui_view_styler' do
|
||||
view.layer.shadowOpacity.should == 0.5
|
||||
view.layer.shadowPath.should == UIBezierPath.bezierPathWithRect(view.bounds).CGPath
|
||||
end
|
||||
|
||||
describe "background_gradient" do
|
||||
before do
|
||||
@view = UIView.alloc.init
|
||||
end
|
||||
|
||||
it "should raise if you do not provide colors and locations" do
|
||||
should.raise(StandardError) do
|
||||
rmq(@view).style do |st|
|
||||
st.background_gradient = { locations: [0, 1] }
|
||||
end
|
||||
end
|
||||
|
||||
should.raise(StandardError) do
|
||||
rmq(@view).style do |st|
|
||||
st.background_gradient = { colors: [rmq.color.red, rmq.color.blue] }
|
||||
end
|
||||
end
|
||||
|
||||
should.not.raise(StandardError) do
|
||||
rmq(@view).style do |st|
|
||||
st.background_gradient = {
|
||||
colors: [rmq.color.red, rmq.color.blue],
|
||||
locations: [0.0, 1.0]
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user