lib/under_os/ui/style/outlining.rb in under-os-1.2.1 vs lib/under_os/ui/style/outlining.rb in under-os-1.3.0
- old
+ new
@@ -86,13 +86,85 @@
def borderWidth=(width)
@view.layer.borderWidth = width
end
+ def boxShadow
+ get_layer_shadow @view.layer
+ end
+
+ def boxShadow=(value)
+ set_layer_shadow @view.layer, value
+ end
+
+ def textShadow
+ get_layer_shadow text_layer
+ end
+
+ def textShadow=(value)
+ set_layer_shadow text_layer, value
+ end
+
private
def convert_color(color)
UnderOs::Color.new(color).ui
+ end
+
+ def text_layer
+ @view.is_a?(UIButton) ? @view.titleLabel : @view.layer
+ end
+
+ def get_layer_shadow(layer)
+ [
+ layer.shadowOffset.width,
+ layer.shadowOffset.height,
+ layer.shadowRadius,
+ layer.shadowOpacity,
+ UnderOs::Color.new(layer.shadowColor).to_hex
+ ].compact.join(" ")
+ end
+
+ def set_layer_shadow(layer, value)
+ x, y, radius, opacity, color = parse_shadow_params(value)
+
+ layer.shadowOffset = CGSizeMake(x, y) if x && y
+ layer.shadowColor = color.CGColor if color
+ layer.shadowRadius = radius if radius
+ layer.shadowOpacity = opacity if opacity
+ layer.shadowPath = UIBezierPath.bezierPathWithRect(@view.layer.bounds).CGPath
+ end
+
+ def parse_shadow_params(string)
+ x, y, radius, opacity, color = string.strip.split
+
+ x = x.gsub /px$/, ''
+ y = y.gsub /px$/, ''
+ radius = radius.gsub /px$/, '' if radius
+ opacity = opacity.gsub /px$/, '' if opacity
+
+ if ! color
+ if opacity
+ unless opacity =~ /^[\d\.]+$/
+ color = opacity
+ opacity = nil
+ end
+ elsif radius
+ unless radius =~ /^[\d\.]+$/
+ color = radius
+ radius = nil
+ end
+ end
+ end
+
+ x = x.to_f if x
+ y = y.to_f if y
+
+ radius = radius.to_f if radius
+ opacity = opacity.to_f if opacity
+ color = convert_color(color) if color
+
+ [x, y, radius, opacity, color]
end
end
end
end