sugarcube 0.8.3 → 0.8.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -59,6 +59,8 @@ Examples
59
59
 
60
60
  ```ruby
61
61
  [1, 3].nsindexpath # NSIndexPath.indexPathWithIndex(1).indexPathByAddingIndex(3)
62
+ [160, 210, 242].uicolor # => UIColor.colorWithRed(0.6274, green:0.8235, blue:0.9490, alpha:1.0)
63
+ [160, 210, 242].uicolor(0.5) # => UIColor.colorWithRed(0.6274, green:0.8235, blue:0.9490, alpha:0.5)
62
64
  ```
63
65
 
64
66
  Fixnum
@@ -169,7 +171,7 @@ This is the "big daddy". Lots of sugar here...
169
171
  # adding them as I come across them.
170
172
  :automatic.uitablerowanimation # or .uitableviewrowanimation
171
173
  :default.uitablecellstyle # or .uitableviewcellstyle
172
- :disclosue.uitablecellaccessory # or .uitableviewcellaccessorytype
174
+ :disclosure.uitablecellaccessory # or .uitableviewcellaccessorytype
173
175
  :blue.uitablecellselectionstyle # or .uitableviewcellselectionstyle
174
176
  ```
175
177
 
@@ -209,6 +211,8 @@ UIAlertView.alert "I mean, is this cool?", buttons: %w[No! Sure! Hmmmm]
209
211
  --------
210
212
 
211
213
  ```ruby
214
+ UIView.first_responder # => returns the first responder, starting at UIApplication.sharedApplication.keyWindow
215
+ my_view.first_responder # => also returns the first responder, but starts looking in my_view
212
216
  self.view << subview # => self.view.addSubview(subview)
213
217
  self.view.show # => self.hidden = false
214
218
  self.view.hide # => self.hidden = true
@@ -168,12 +168,7 @@ module SugarCube
168
168
  ##| TREE
169
169
  def tree(view=nil, tab=nil, is_last=true, views_index=nil)
170
170
  unless view
171
- @@sugarcube_view ||= nil
172
- if @@sugarcube_view
173
- view = @@sugarcube_view
174
- else
175
- view = UIApplication.sharedApplication.keyWindow
176
- end
171
+ view = UIApplication.sharedApplication.keyWindow
177
172
  end
178
173
 
179
174
  if not views_index
@@ -203,13 +198,24 @@ module SugarCube
203
198
  print ". "
204
199
  tab = ""
205
200
  end
206
- puts "#{view.class.name}(##{view.object_id.to_s(16)}, #{view.frame.to_s})"
207
201
 
208
- view.subviews.each_index {|index|
209
- subview = view.subviews[index]
210
- views_index += 1
211
- views_index = tree(subview, tab, index == view.subviews.length - 1, views_index)
212
- }
202
+ if not view
203
+ puts "View is nil (no window or view to display)"
204
+ else
205
+ if self == view
206
+ print "\033[1m"
207
+ end
208
+ puts "#{view.class.name}(##{view.object_id.to_s(16)}, #{view.frame.to_s})"
209
+ if self == view
210
+ print "\033[0m"
211
+ end
212
+
213
+ view.subviews.each_index {|index|
214
+ subview = view.subviews[index]
215
+ views_index += 1
216
+ views_index = tree(subview, tab, index == view.subviews.length - 1, views_index)
217
+ }
218
+ end
213
219
 
214
220
  return is_first ? view : views_index
215
221
  end
@@ -36,4 +36,12 @@ class Array
36
36
  set
37
37
  end
38
38
 
39
+ # [160, 210, 242].uicolor => 0xA0D2F2.uicolor
40
+ def uicolor(alpha=1.0)
41
+ red = self[0] / 255.0
42
+ green = self[1] / 255.0
43
+ blue = self[2] / 255.0
44
+ UIColor.colorWithRed(red, green:green, blue:blue, alpha:alpha.to_f)
45
+ end
46
+
39
47
  end
@@ -9,8 +9,6 @@ class UIAlertView
9
9
  # success: proc{ |pressed| puts "pressed: #{pressed}" },
10
10
  # )
11
11
  def self.alert(title, options={}, &block)
12
- puts options
13
- puts block
14
12
  # create the delegate
15
13
  delegate = SugarCube::AlertViewDelegate.new
16
14
  delegate.on_success = options[:success] || block
@@ -1,5 +1,27 @@
1
1
  class UIView
2
2
 
3
+ class << self
4
+ # returns the first responder, starting at the Window and searching every subview
5
+ def first_responder
6
+ UIApplication.sharedApplication.keyWindow.first_responder
7
+ end
8
+ end
9
+
10
+ # returns the first responder, or nil if it cannot be found
11
+ def first_responder
12
+ if self.firstResponder?
13
+ return self
14
+ end
15
+
16
+ found = nil
17
+ self.subviews.each do |subview|
18
+ found = subview.first_responder
19
+ break if found
20
+ end
21
+
22
+ return found
23
+ end
24
+
3
25
  def <<(view)
4
26
  self.addSubview view
5
27
  end
@@ -1,3 +1,3 @@
1
1
  module SugarCube
2
- Version = '0.8.3'
2
+ Version = '0.8.4'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sugarcube
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.3
4
+ version: 0.8.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -14,7 +14,7 @@ date: 2012-09-11 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake
17
- requirement: &70317230120160 !ruby/object:Gem::Requirement
17
+ requirement: &70283746991220 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: '0'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *70317230120160
25
+ version_requirements: *70283746991220
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: rspec
28
- requirement: &70317230119540 !ruby/object:Gem::Requirement
28
+ requirement: &70283746990680 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,7 +33,7 @@ dependencies:
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
- version_requirements: *70317230119540
36
+ version_requirements: *70283746990680
37
37
  description: ! '== Description
38
38
 
39
39