easy-button 0.0.4 → 0.0.5
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.
- data/README.md +1 -1
- data/easy-button.gemspec +1 -1
- data/lib/easy-button/easy-button.rb +27 -12
- data/spec/easy_button_spec.rb +4 -4
- metadata +4 -3
data/README.md
CHANGED
data/easy-button.gemspec
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
class EasyButton < UIButton
|
2
|
+
attr_writer :backgroundColor
|
2
3
|
attr_accessor :borderRadius, :font, :textColor, :title
|
4
|
+
attr_reader :titleLabel
|
3
5
|
|
4
6
|
def initWithFrame(frame)
|
5
7
|
if super
|
@@ -16,14 +18,21 @@ class EasyButton < UIButton
|
|
16
18
|
end
|
17
19
|
|
18
20
|
def buttonSetup
|
21
|
+
# Custom Title Label
|
22
|
+
self.setTitleColor(UIColor.clearColor, forState:UIControlStateNormal)
|
23
|
+
@titleLabel = UILabel.alloc.initWithFrame(self.bounds)
|
24
|
+
@titleLabel.backgroundColor = UIColor.clearColor
|
25
|
+
@titleLabel.shadowColor = UIColor.colorWithWhite(0, alpha:0.5);
|
26
|
+
@titleLabel.shadowOffset = [0, -1]
|
27
|
+
@titleLabel.textAlignment = UITextAlignmentCenter
|
28
|
+
self.addSubview(@titleLabel)
|
29
|
+
|
19
30
|
self.opaque = false
|
20
31
|
self.backgroundColor = UIColor.clearColor
|
21
32
|
self.backgroundColor = "#ff0000"
|
22
33
|
self.borderRadius = 10
|
23
34
|
self.font = UIFont.boldSystemFontOfSize(18)
|
24
35
|
self.textColor = '#fff'
|
25
|
-
titleLabel.shadowColor = UIColor.colorWithWhite(0, alpha:0.5);
|
26
|
-
titleLabel.shadowOffset = [0, -1]
|
27
36
|
end
|
28
37
|
|
29
38
|
def backgroundColor=(value)
|
@@ -41,31 +50,37 @@ class EasyButton < UIButton
|
|
41
50
|
@backgroundColorBottom = value
|
42
51
|
end
|
43
52
|
self.setNeedsDisplay
|
53
|
+
self
|
44
54
|
end
|
45
55
|
|
46
56
|
def borderRadius=(value)
|
47
57
|
@borderRadius = value
|
48
58
|
self.setNeedsDisplay
|
59
|
+
self
|
60
|
+
end
|
61
|
+
|
62
|
+
def font=(value)
|
63
|
+
@font = value
|
64
|
+
@titleLabel.setFont(@font)
|
65
|
+
self
|
49
66
|
end
|
50
67
|
|
51
68
|
def textColor=(value)
|
52
69
|
@textColor = value
|
53
70
|
if value.is_a? String
|
54
71
|
red, green, blue = rgbFromHex(value)
|
55
|
-
titleLabel.textColor = UIColor.colorWithRed(red, green:green, blue:blue, alpha:1)
|
72
|
+
@titleLabel.textColor = UIColor.colorWithRed(red, green:green, blue:blue, alpha:1)
|
56
73
|
else
|
57
|
-
titleLabel.textColor = value
|
74
|
+
@titleLabel.textColor = value
|
58
75
|
end
|
59
|
-
|
60
|
-
|
61
|
-
def font=(value)
|
62
|
-
@font = value
|
63
|
-
titleLabel.setFont(@font)
|
76
|
+
self
|
64
77
|
end
|
65
78
|
|
66
79
|
def title=(value)
|
67
80
|
@title = value
|
68
|
-
|
81
|
+
@titleLabel.text = @title
|
82
|
+
self.setTitle(@title, forState:UIControlStateNormal) # For Accessibility
|
83
|
+
self
|
69
84
|
end
|
70
85
|
|
71
86
|
def drawRect(rect)
|
@@ -129,9 +144,9 @@ class EasyButton < UIButton
|
|
129
144
|
CGContextRestoreGState(context)
|
130
145
|
|
131
146
|
# Move Title Label Down When Pressed
|
147
|
+
@titleLabel.transform = CGAffineTransformIdentity
|
132
148
|
if self.state == UIControlStateHighlighted
|
133
|
-
titleLabel.transform =
|
134
|
-
titleLabel.transform = CGAffineTransformMakeTranslation(0, 1)
|
149
|
+
@titleLabel.transform = CGAffineTransformMakeTranslation(0, 1)
|
135
150
|
end
|
136
151
|
end
|
137
152
|
|
data/spec/easy_button_spec.rb
CHANGED
@@ -3,10 +3,6 @@ describe EasyButton do
|
|
3
3
|
@easyButton = EasyButton.alloc.initWithFrame([[0.0, 0.0], [10.0, 50.0]])
|
4
4
|
end
|
5
5
|
|
6
|
-
it "backgroundColor should be transparent" do
|
7
|
-
@easyButton.backgroundColor.should.equal UIColor.clearColor
|
8
|
-
end
|
9
|
-
|
10
6
|
it "borderRadius should have a default value" do
|
11
7
|
@easyButton.borderRadius.should.equal 10
|
12
8
|
end
|
@@ -44,4 +40,8 @@ describe EasyButton do
|
|
44
40
|
@easyButton.textColor = textColor
|
45
41
|
@easyButton.titleLabel.textColor.should.equal UIColor.colorWithRed(0, green:0, blue:0, alpha:1)
|
46
42
|
end
|
43
|
+
|
44
|
+
it "should raise an error for bad textColor hex code" do
|
45
|
+
lambda { @easyButton.textColor = '#ff00' }.should.raise(ArgumentError, 'Argument is not a valid hex code.')
|
46
|
+
end
|
47
47
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: easy-button
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-06-
|
12
|
+
date: 2012-06-15 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: A nice looking button in RubyMotion
|
15
15
|
email:
|
@@ -43,8 +43,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
43
43
|
version: '0'
|
44
44
|
requirements: []
|
45
45
|
rubyforge_project:
|
46
|
-
rubygems_version: 1.8.
|
46
|
+
rubygems_version: 1.8.10
|
47
47
|
signing_key:
|
48
48
|
specification_version: 3
|
49
49
|
summary: Extends to UIButton class and adds properties for easy styling.
|
50
50
|
test_files: []
|
51
|
+
has_rdoc:
|