easy-button 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -29,7 +29,7 @@ Gemfile
29
29
  ```ruby
30
30
  source :rubygems
31
31
 
32
- gem 'easy-button', :git => 'git://github.com/brianpattison/easy-button.git'
32
+ gem 'easy-button'
33
33
  ```
34
34
 
35
35
  Run `bundle install`.
@@ -8,5 +8,5 @@ Gem::Specification.new do |gem|
8
8
  gem.files = `git ls-files`.split($\)
9
9
  gem.name = "easy-button"
10
10
  gem.require_paths = ["lib"]
11
- gem.version = '0.0.4'
11
+ gem.version = '0.0.5'
12
12
  end
@@ -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
- end
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
- self.setTitle(@title, forState:UIControlStateNormal)
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 = CGAffineTransformIdentity
134
- titleLabel.transform = CGAffineTransformMakeTranslation(0, 1)
149
+ @titleLabel.transform = CGAffineTransformMakeTranslation(0, 1)
135
150
  end
136
151
  end
137
152
 
@@ -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
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-07 00:00:00.000000000Z
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.6
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: