under-os-ui 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/README.md +26 -0
- data/lib/assets/fontawesome-webfont.ttf +0 -0
- data/lib/assets/under-os.css +115 -0
- data/lib/core/kernel.rb +16 -0
- data/lib/under-os-ui.rb +6 -0
- data/lib/under_os/app.rb +26 -0
- data/lib/under_os/config.rb +25 -0
- data/lib/under_os/history.rb +53 -0
- data/lib/under_os/page.rb +178 -0
- data/lib/under_os/page/builder.rb +96 -0
- data/lib/under_os/page/layout.rb +43 -0
- data/lib/under_os/page/matcher.rb +128 -0
- data/lib/under_os/page/stylesheet.rb +67 -0
- data/lib/under_os/parser.rb +24 -0
- data/lib/under_os/parser/css.rb +37 -0
- data/lib/under_os/parser/html.rb +97 -0
- data/lib/under_os/ui.rb +3 -0
- data/lib/under_os/ui/alert.rb +52 -0
- data/lib/under_os/ui/button.rb +42 -0
- data/lib/under_os/ui/collection.rb +65 -0
- data/lib/under_os/ui/collection/cell.rb +21 -0
- data/lib/under_os/ui/collection/delegate.rb +70 -0
- data/lib/under_os/ui/collection/item.rb +32 -0
- data/lib/under_os/ui/collection/layout.rb +43 -0
- data/lib/under_os/ui/collection/styles.rb +15 -0
- data/lib/under_os/ui/div.rb +3 -0
- data/lib/under_os/ui/form.rb +60 -0
- data/lib/under_os/ui/icon.rb +61 -0
- data/lib/under_os/ui/icon/awesome.rb +376 -0
- data/lib/under_os/ui/icon/engine.rb +9 -0
- data/lib/under_os/ui/image.rb +31 -0
- data/lib/under_os/ui/input.rb +140 -0
- data/lib/under_os/ui/label.rb +21 -0
- data/lib/under_os/ui/locker.rb +42 -0
- data/lib/under_os/ui/navbar.rb +123 -0
- data/lib/under_os/ui/progress.rb +17 -0
- data/lib/under_os/ui/scroll.rb +102 -0
- data/lib/under_os/ui/select.rb +95 -0
- data/lib/under_os/ui/sidebar.rb +45 -0
- data/lib/under_os/ui/slider.rb +37 -0
- data/lib/under_os/ui/spinner.rb +23 -0
- data/lib/under_os/ui/style.rb +21 -0
- data/lib/under_os/ui/style/fonts.rb +56 -0
- data/lib/under_os/ui/style/margins.rb +164 -0
- data/lib/under_os/ui/style/outlining.rb +170 -0
- data/lib/under_os/ui/style/positioning.rb +183 -0
- data/lib/under_os/ui/switch.rb +26 -0
- data/lib/under_os/ui/textarea.rb +19 -0
- data/lib/under_os/ui/utils/animation.rb +101 -0
- data/lib/under_os/ui/utils/commons.rb +70 -0
- data/lib/under_os/ui/utils/dimensions.rb +37 -0
- data/lib/under_os/ui/utils/events.rb +210 -0
- data/lib/under_os/ui/utils/manipulation.rb +44 -0
- data/lib/under_os/ui/utils/position.rb +21 -0
- data/lib/under_os/ui/utils/size.rb +21 -0
- data/lib/under_os/ui/utils/styles.rb +89 -0
- data/lib/under_os/ui/utils/traversing.rb +44 -0
- data/lib/under_os/ui/utils/wrap.rb +77 -0
- data/lib/under_os/ui/view.rb +31 -0
- data/spec/assets/app.css +13 -0
- data/spec/assets/test.css +7 -0
- data/spec/assets/test.html +3 -0
- data/spec/assets/test.png +0 -0
- data/spec/assets/test_page.rb +2 -0
- data/spec/under_os/page/builder_spec.rb +128 -0
- data/spec/under_os/page/layout_spec.rb +18 -0
- data/spec/under_os/page/matcher_spec.rb +260 -0
- data/spec/under_os/page/stylesheet_spec.rb +83 -0
- data/spec/under_os/page_spec.rb +5 -0
- data/spec/under_os/parser/css_spec.rb +77 -0
- data/spec/under_os/parser/html_spec.rb +152 -0
- data/spec/under_os/parser_spec.rb +16 -0
- data/spec/under_os/ui/button_spec.rb +50 -0
- data/spec/under_os/ui/collection_spec.rb +19 -0
- data/spec/under_os/ui/div_spec.rb +24 -0
- data/spec/under_os/ui/form_spec.rb +156 -0
- data/spec/under_os/ui/icon_spec.rb +57 -0
- data/spec/under_os/ui/image_spec.rb +39 -0
- data/spec/under_os/ui/input_spec.rb +109 -0
- data/spec/under_os/ui/label_spec.rb +22 -0
- data/spec/under_os/ui/locker_spec.rb +31 -0
- data/spec/under_os/ui/progress_spec.rb +31 -0
- data/spec/under_os/ui/scroll_spec.rb +75 -0
- data/spec/under_os/ui/select_spec.rb +135 -0
- data/spec/under_os/ui/sidebar_spec.rb +35 -0
- data/spec/under_os/ui/slider_spec.rb +69 -0
- data/spec/under_os/ui/spinner_spec.rb +57 -0
- data/spec/under_os/ui/style/fonts_spec.rb +111 -0
- data/spec/under_os/ui/style/margins_spec.rb +106 -0
- data/spec/under_os/ui/style/outlining_spec.rb +101 -0
- data/spec/under_os/ui/style/positioning_spec.rb +69 -0
- data/spec/under_os/ui/style_spec.rb +19 -0
- data/spec/under_os/ui/switch_spec.rb +60 -0
- data/spec/under_os/ui/textarea_spec.rb +34 -0
- data/spec/under_os/ui/utils/commons_spec.rb +81 -0
- data/spec/under_os/ui/utils/events_spec.rb +87 -0
- data/spec/under_os/ui/utils/manipulation_spec.rb +130 -0
- data/spec/under_os/ui/utils/styles_spec.rb +140 -0
- data/spec/under_os/ui/utils/traversing_spec.rb +124 -0
- data/spec/under_os/ui/utils/wrap_spec.rb +69 -0
- data/spec/under_os/ui/view_spec.rb +39 -0
- data/under-os-ui.gemspec +23 -0
- metadata +216 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
class UnderOs::UI::Slider < UnderOs::UI::Input
|
|
2
|
+
wraps UISlider, tag: 'slider'
|
|
3
|
+
|
|
4
|
+
def initialize(options={})
|
|
5
|
+
super
|
|
6
|
+
|
|
7
|
+
self.min = options[:min] if options[:min]
|
|
8
|
+
self.max = options[:max] if options[:max]
|
|
9
|
+
|
|
10
|
+
@_.continuous = options.delete(:track) || true # track the changes as they go
|
|
11
|
+
@_.addTarget self, action: :handle_change, forControlEvents:UIControlEventValueChanged
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def value
|
|
15
|
+
@_.value
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def value=(value)
|
|
19
|
+
@_.value = value.to_f
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def min
|
|
23
|
+
@_.minimumValue
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def min=(value)
|
|
27
|
+
@_.minimumValue = value.to_f
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def max
|
|
31
|
+
@_.maximumValue
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def max=(value)
|
|
35
|
+
@_.maximumValue = value.to_f
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
class UnderOs::UI::Spinner < UnderOs::UI::View
|
|
2
|
+
wraps UIActivityIndicatorView, tag: :spinner
|
|
3
|
+
|
|
4
|
+
def initialize(options={})
|
|
5
|
+
super
|
|
6
|
+
show
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def show
|
|
10
|
+
@_.startAnimating
|
|
11
|
+
self
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def hide
|
|
15
|
+
@_.stopAnimating
|
|
16
|
+
self
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def hidden
|
|
20
|
+
@_.isAnimating == 0
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
#
|
|
2
|
+
# The view styles handling wrapper
|
|
3
|
+
#
|
|
4
|
+
# The idea here is to provide a DOM like `style` object,
|
|
5
|
+
# which can take similar to DOM properties and translate
|
|
6
|
+
# them into iOS equivalents
|
|
7
|
+
#
|
|
8
|
+
class UnderOs::UI::Style
|
|
9
|
+
include Fonts
|
|
10
|
+
include Margins
|
|
11
|
+
include Outlining
|
|
12
|
+
include Positioning
|
|
13
|
+
|
|
14
|
+
attr_reader :view
|
|
15
|
+
|
|
16
|
+
def initialize(view, type)
|
|
17
|
+
@view = view
|
|
18
|
+
@type = type
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
end
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
#
|
|
2
|
+
# This module handles all sorts of things related to fonts
|
|
3
|
+
# and text attributes
|
|
4
|
+
#
|
|
5
|
+
module UnderOs::UI
|
|
6
|
+
class Style
|
|
7
|
+
module Fonts
|
|
8
|
+
def fontFamily
|
|
9
|
+
@view.font.familyName
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def fontFamily=(value)
|
|
13
|
+
@view.font = UIFont.fontWithName(value, size: @view.font.pointSize)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def fontSize
|
|
17
|
+
@view.font.pointSize
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def fontSize=(value)
|
|
21
|
+
@view.font = @view.font.fontWithSize(value)
|
|
22
|
+
@view.sizeToFit if @type == :icon
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def textAlign
|
|
26
|
+
if @view.is_a?(UIButton)
|
|
27
|
+
BUTTONS_ALIGMENTS_MAP.key(@view.contentHorizontalAlignment)
|
|
28
|
+
elsif @view.respond_to?(:textAlignment)
|
|
29
|
+
TEXTNODES_ALIGMENTS_MAP.key(@view.textAlignment)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def textAlign=(value)
|
|
34
|
+
if @view.is_a?(UIButton)
|
|
35
|
+
@view.contentHorizontalAlignment = BUTTONS_ALIGMENTS_MAP[value.to_s] || BUTTONS_ALIGMENTS_MAP['left']
|
|
36
|
+
elsif @view.respond_to?(:textAlignment)
|
|
37
|
+
@view.textAlignment = TEXTNODES_ALIGMENTS_MAP[value.to_s] || BUTTONS_ALIGMENTS_MAP['left']
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
BUTTONS_ALIGMENTS_MAP = {
|
|
42
|
+
'right' => UIControlContentHorizontalAlignmentRight,
|
|
43
|
+
'center' => UIControlContentHorizontalAlignmentCenter,
|
|
44
|
+
'justify' => UIControlContentHorizontalAlignmentFill,
|
|
45
|
+
'left' => UIControlContentHorizontalAlignmentLeft
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
TEXTNODES_ALIGMENTS_MAP = {
|
|
49
|
+
'right' => NSTextAlignmentRight,
|
|
50
|
+
'center' => NSTextAlignmentCenter,
|
|
51
|
+
'justify' => NSTextAlignmentJustified,
|
|
52
|
+
'left' => NSTextAlignmentLeft
|
|
53
|
+
}
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
#
|
|
2
|
+
# This module handles styles related to margins and paddings
|
|
3
|
+
#
|
|
4
|
+
module UnderOs::UI
|
|
5
|
+
class Style
|
|
6
|
+
module Margins
|
|
7
|
+
def display
|
|
8
|
+
@display || :block
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def display=(value)
|
|
12
|
+
@display = %w[none block inline].include?(value.to_s) ? value.to_sym : :block
|
|
13
|
+
@view.hidden = @display == :none
|
|
14
|
+
set_offsets if @display == :inline
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def margin
|
|
18
|
+
[marginTop, marginRight, marginBottom, marginLeft]
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def margin=(value)
|
|
22
|
+
@margin_top, @margin_right, @margin_botom, @margin_left = to_4dim_array(value)
|
|
23
|
+
set_offsets
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def marginTop
|
|
27
|
+
@margin_top || 0
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def marginTop=(value)
|
|
31
|
+
@margin_top = value
|
|
32
|
+
set_offsets
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def marginLeft
|
|
36
|
+
@margin_left || 0
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def marginLeft=(value)
|
|
40
|
+
@margin_left = value
|
|
41
|
+
set_offsets
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def marginRight
|
|
45
|
+
@margin_right || 0
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def marginRight=(value)
|
|
49
|
+
@margin_right = value
|
|
50
|
+
set_offsets
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def marginBottom
|
|
54
|
+
@margin_botom || 0
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def marginBottom=(value)
|
|
58
|
+
@margin_botom = value
|
|
59
|
+
set_offsets
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def padding
|
|
63
|
+
[paddingTop, paddingRight, paddingBottom, paddingLeft]
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def padding=(value)
|
|
67
|
+
@padding_top, @padding_right, @padding_botom, @padding_left = to_4dim_array(value)
|
|
68
|
+
set_offsets
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def paddingTop
|
|
72
|
+
@padding_top || 0
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def paddingTop=(value)
|
|
76
|
+
@padding_top = value
|
|
77
|
+
set_paddings
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def paddingLeft
|
|
81
|
+
@padding_left || 0
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def paddingLeft=(value)
|
|
85
|
+
@padding_left = value
|
|
86
|
+
set_paddings
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def paddingRight
|
|
90
|
+
@padding_right || 0
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def paddingRight=(value)
|
|
94
|
+
@padding_right = value
|
|
95
|
+
set_paddings
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def paddingBottom
|
|
99
|
+
@padding_botom || 0
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def paddingBottom=(value)
|
|
103
|
+
@padding_botom = value
|
|
104
|
+
set_paddings
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
private
|
|
108
|
+
|
|
109
|
+
def to_4dim_array(value)
|
|
110
|
+
value = value.gsub('px', '').split.map(&:to_f) if value.is_a?(String)
|
|
111
|
+
value = Array(value)
|
|
112
|
+
case value.size
|
|
113
|
+
when 1 then value * 4
|
|
114
|
+
when 2 then [value[0], value[1], value[0], value[1]]
|
|
115
|
+
else value
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def set_offsets
|
|
120
|
+
return nil if display != :inline
|
|
121
|
+
|
|
122
|
+
position_x = marginLeft + parent_offset_x
|
|
123
|
+
position_y = marginTop
|
|
124
|
+
|
|
125
|
+
@view.frame = [[position_x, position_y], [
|
|
126
|
+
@view.frame.size.width, @view.frame.size.height
|
|
127
|
+
]]
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def set_paddings
|
|
131
|
+
if @view.respond_to?(:contentEdgeInsets)
|
|
132
|
+
@view.contentEdgeInsets = UIEdgeInsetsMake(paddingTop, paddingLeft, paddingBottom, paddingRight)
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
def parent_offset_x
|
|
137
|
+
offset = 0
|
|
138
|
+
parent_frame = parent_view_frame
|
|
139
|
+
|
|
140
|
+
if parent_frame
|
|
141
|
+
offset += parent_frame.origin.x + parent_frame.size.width
|
|
142
|
+
|
|
143
|
+
if wrap = UnderOs::UI::View.wrap_for(@view)
|
|
144
|
+
offset += wrap.style.marginRight
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
offset
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
def parent_view_frame
|
|
152
|
+
parent_view = @view.superview
|
|
153
|
+
parent_frame = nil
|
|
154
|
+
|
|
155
|
+
unless parent_view.subviews[0] === @view
|
|
156
|
+
previous_view = parent_view.subviews[parent_view.subviews.index(@view)-1]
|
|
157
|
+
parent_frame = previous_view && previous_view.frame
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
parent_frame
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
end
|
|
164
|
+
end
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
#
|
|
2
|
+
# This module contains things like colors, borders, shadows, etc
|
|
3
|
+
#
|
|
4
|
+
module UnderOs::UI
|
|
5
|
+
class Style
|
|
6
|
+
module Outlining
|
|
7
|
+
def opacity
|
|
8
|
+
@view.alpha
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def opacity=(value)
|
|
12
|
+
@view.alpha = value
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def backgroundColor
|
|
16
|
+
@view.backgroundColor
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def backgroundColor=(color, state=UIControlStateNormal)
|
|
20
|
+
if @view.is_a?(UIButton)
|
|
21
|
+
@view.setBackgroundColor convert_color(color), forState:state
|
|
22
|
+
else
|
|
23
|
+
@view.backgroundColor = convert_color(color)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def backgroundImage
|
|
28
|
+
@background_image
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def backgroundImage=(image)
|
|
32
|
+
image = UIImage.UIImage.imageNamed(image) if image.is_a?(String)
|
|
33
|
+
|
|
34
|
+
if @view.is_a?(UIButton)
|
|
35
|
+
@view.setBackgroundImage(image, forState:UIControlStateNormal)
|
|
36
|
+
else
|
|
37
|
+
@background_image = UnderOs::UI::Image.new(src: image, class: 'uos-background-image')
|
|
38
|
+
@background_image._.frame = [[0, 0], [@view.frame.size.width, @view.frame.size.height]]
|
|
39
|
+
@view.insertSubview(@background_image._, atIndex: 0)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
alias :background :backgroundColor
|
|
44
|
+
alias :background= :backgroundColor=
|
|
45
|
+
|
|
46
|
+
def color(state=UIControlStateNormal)
|
|
47
|
+
if @view.is_a?(UIButton)
|
|
48
|
+
@view.titleColorForState(state)
|
|
49
|
+
elsif @view.respond_to?(:textColor)
|
|
50
|
+
@view.textColor
|
|
51
|
+
elsif @view.respond_to?(:color)
|
|
52
|
+
@view.color
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def color=(color, state=UIControlStateNormal)
|
|
57
|
+
if @view.is_a?(UIButton)
|
|
58
|
+
@view.setTitleColor convert_color(color), forState:state
|
|
59
|
+
elsif @view.respond_to?(:textColor)
|
|
60
|
+
@view.textColor = convert_color(color)
|
|
61
|
+
elsif @view.respond_to?(:color)
|
|
62
|
+
@view.color = convert_color(color)
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def borderRadius
|
|
67
|
+
@view.layer.cornerRadius
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def borderRadius=(radius)
|
|
71
|
+
@view.clipsToBounds = true
|
|
72
|
+
@view.layer.cornerRadius = radius
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def borderColor
|
|
76
|
+
@view.layer.borderColor
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def borderColor=(color)
|
|
80
|
+
@view.layer.borderColor = convert_color(color).CGColor
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def borderWidth
|
|
84
|
+
@view.layer.borderWidth
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def borderWidth=(width)
|
|
88
|
+
@view.layer.borderWidth = width
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def boxShadow
|
|
92
|
+
get_layer_shadow @view.layer
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def boxShadow=(value)
|
|
96
|
+
set_layer_shadow @view.layer, value
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def textShadow
|
|
100
|
+
get_layer_shadow text_layer
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def textShadow=(value)
|
|
104
|
+
set_layer_shadow text_layer, value
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
private
|
|
108
|
+
|
|
109
|
+
def convert_color(color)
|
|
110
|
+
UnderOs::Color.new(color).ui
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def text_layer
|
|
114
|
+
@view.is_a?(UIButton) ? @view.titleLabel : @view.layer
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
def get_layer_shadow(layer)
|
|
118
|
+
[
|
|
119
|
+
layer.shadowOffset.width,
|
|
120
|
+
layer.shadowOffset.height,
|
|
121
|
+
layer.shadowRadius,
|
|
122
|
+
layer.shadowOpacity,
|
|
123
|
+
UnderOs::Color.new(layer.shadowColor).to_hex
|
|
124
|
+
].compact.join(" ")
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def set_layer_shadow(layer, value)
|
|
128
|
+
x, y, radius, opacity, color = parse_shadow_params(value)
|
|
129
|
+
|
|
130
|
+
layer.shadowOffset = CGSizeMake(x, y) if x && y
|
|
131
|
+
layer.shadowColor = color.CGColor if color
|
|
132
|
+
layer.shadowRadius = radius if radius
|
|
133
|
+
layer.shadowOpacity = opacity if opacity
|
|
134
|
+
layer.shadowPath = UIBezierPath.bezierPathWithRect(@view.layer.bounds).CGPath
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
def parse_shadow_params(string)
|
|
138
|
+
x, y, radius, opacity, color = string.strip.split
|
|
139
|
+
|
|
140
|
+
x = x.gsub /px$/, ''
|
|
141
|
+
y = y.gsub /px$/, ''
|
|
142
|
+
radius = radius.gsub /px$/, '' if radius
|
|
143
|
+
opacity = opacity.gsub /px$/, '' if opacity
|
|
144
|
+
|
|
145
|
+
if ! color
|
|
146
|
+
if opacity
|
|
147
|
+
unless opacity =~ /^[\d\.]+$/
|
|
148
|
+
color = opacity
|
|
149
|
+
opacity = nil
|
|
150
|
+
end
|
|
151
|
+
elsif radius
|
|
152
|
+
unless radius =~ /^[\d\.]+$/
|
|
153
|
+
color = radius
|
|
154
|
+
radius = nil
|
|
155
|
+
end
|
|
156
|
+
end
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
x = x.to_f if x
|
|
160
|
+
y = y.to_f if y
|
|
161
|
+
|
|
162
|
+
radius = radius.to_f if radius
|
|
163
|
+
opacity = opacity.to_f if opacity
|
|
164
|
+
color = convert_color(color) if color
|
|
165
|
+
|
|
166
|
+
[x, y, radius, opacity, color]
|
|
167
|
+
end
|
|
168
|
+
end
|
|
169
|
+
end
|
|
170
|
+
end
|