OTGHelpers 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +76 -0
- data/lib/OTGHelpers.rb +10 -0
- data/lib/project/ns_string.rb +12 -0
- data/lib/project/ui_image.rb +28 -0
- data/lib/project/ui_label.rb +18 -0
- data/lib/project/ui_view.rb +47 -0
- data/lib/project/version.rb +3 -0
- metadata +65 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 23c964b4adcc7e1031874e8b824f426a5ba731cd
|
4
|
+
data.tar.gz: 00a864cf631979ccce71453ffe33746064885bf6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 509346ac8df21ae64104d7e99c49e71a17c10a15e1d27d9d9c04c97d6b53b1d17e99397746f844fb66d77716f8bb64435863815112620598bfab98e3c867762e
|
7
|
+
data.tar.gz: a6e8092fd789641a23fb54d0dc1ad180c9e4549edafacd80a4886a00e5e9833a0ce652d55d6467c32df2bfbafc7785d5309934abda67b59822b3090d112ff326
|
data/README.md
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
# OTGHelpers
|
2
|
+
|
3
|
+
A set of class extenstions I commonly use in my applications for RubyMotion.
|
4
|
+
|
5
|
+
## Current additions:
|
6
|
+
|
7
|
+
### UILabel
|
8
|
+
|
9
|
+
#### `auto_height_for_width(change_width=false)`
|
10
|
+
|
11
|
+
Automatically resizes a UILabel's height based on its contents. Optionally, it can shrink the width as well.
|
12
|
+
|
13
|
+
### NSString
|
14
|
+
|
15
|
+
#### `uiimage`
|
16
|
+
|
17
|
+
Runs `UIImage.imageNamed(self)` for the string.
|
18
|
+
|
19
|
+
#### `nsurl`
|
20
|
+
|
21
|
+
Returns the string as an `NSURL`
|
22
|
+
|
23
|
+
### UIView
|
24
|
+
|
25
|
+
#### `add_borders(locations, color, width = 1)` aliased as `add_border`
|
26
|
+
|
27
|
+
Adds borders in specified locations on a `UIView`. Possible locations are: `[:top, :left, :right, :bottom]` and can be passed singularly or in an array.
|
28
|
+
|
29
|
+
#### `add_top_border(color, width)`
|
30
|
+
#### `add_right_border(color, width)`
|
31
|
+
#### `add_bottom_border(color, width)`
|
32
|
+
#### `add_left_border(color, width)`
|
33
|
+
|
34
|
+
These methods are used by the `add_borders` method and can be called independently if needed.
|
35
|
+
|
36
|
+
#### `remove_borders` aliased as `remove_border`
|
37
|
+
|
38
|
+
Removes all borders you've added on a UIView (may also remove other things you've added to the view's `layer`, so be careful with this one!)
|
39
|
+
|
40
|
+
### UIImage
|
41
|
+
|
42
|
+
#### `pad_to(size, args={})`
|
43
|
+
|
44
|
+
Pads the size of an image to the specified size.
|
45
|
+
|
46
|
+
#### `template`
|
47
|
+
|
48
|
+
Returns a UIImage with UIImageRenderingModeAlwaysTemplate
|
49
|
+
|
50
|
+
## Installation
|
51
|
+
|
52
|
+
Add this line to your application's Gemfile:
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
gem 'OTGHelpers'
|
56
|
+
```
|
57
|
+
|
58
|
+
And then execute:
|
59
|
+
|
60
|
+
```bash
|
61
|
+
$ bundle
|
62
|
+
```
|
63
|
+
|
64
|
+
Or install it yourself as:
|
65
|
+
|
66
|
+
```bash
|
67
|
+
$ gem install OTGHelpers
|
68
|
+
```
|
69
|
+
|
70
|
+
## Contributing
|
71
|
+
|
72
|
+
1. Fork it
|
73
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
74
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
75
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
76
|
+
5. Create new Pull Request
|
data/lib/OTGHelpers.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
unless defined?(Motion::Project::Config)
|
4
|
+
raise "This file must be required within a RubyMotion project Rakefile."
|
5
|
+
end
|
6
|
+
|
7
|
+
lib_dir_path = File.dirname(File.expand_path(__FILE__))
|
8
|
+
Motion::Project::App.setup do |app|
|
9
|
+
app.files.unshift(Dir.glob(File.join(lib_dir_path, "project/**/*.rb")))
|
10
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
class UIImage
|
2
|
+
# Pads an image with transparency around it.
|
3
|
+
# Requires Sugarcube
|
4
|
+
def pad_to(s, args={})
|
5
|
+
s = CGSizeMake(s[0], s[1]) if s.is_a?(Array)
|
6
|
+
UIImage.canvas(size: s) do |context|
|
7
|
+
|
8
|
+
if args[:background]
|
9
|
+
args[:background].setFill
|
10
|
+
CGContextAddRect(context, [[0, 0], s])
|
11
|
+
CGContextDrawPath(context, KCGPathFill)
|
12
|
+
end
|
13
|
+
|
14
|
+
if args[:at] == :top_left
|
15
|
+
origin = CGPointMake(0, 0)
|
16
|
+
else
|
17
|
+
origin = CGPointMake((s.width - self.size.width) / 2, (s.height - self.size.height) / 2)
|
18
|
+
end
|
19
|
+
self.drawAtPoint(origin)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# Returns a UIImage with UIImageRenderingModeAlwaysTemplate
|
24
|
+
def template
|
25
|
+
self.imageWithRenderingMode(UIImageRenderingModeAlwaysTemplate)
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class UILabel
|
2
|
+
def auto_height_for_width(change_width = false)
|
3
|
+
self.lineBreakMode = UILineBreakModeWordWrap
|
4
|
+
self.numberOfLines = 0
|
5
|
+
maximumLabelSize = CGSizeMake(self.frame.size.width, Float::MAX)
|
6
|
+
|
7
|
+
attributedText = NSAttributedString.alloc.initWithString(self.text, attributes:{NSFontAttributeName => self.font})
|
8
|
+
rect = attributedText.boundingRectWithSize([self.frame.size.width, Float::MAX], options:NSStringDrawingUsesLineFragmentOrigin, context:nil)
|
9
|
+
|
10
|
+
w = change_width ? rect.size.width.ceil : self.frame.size.width
|
11
|
+
expected_label_size = [w, rect.size.height.ceil]
|
12
|
+
|
13
|
+
new_frame = [self.frame.origin, expected_label_size]
|
14
|
+
self.frame = new_frame
|
15
|
+
end
|
16
|
+
alias :autoHeightForWidth :auto_height_for_width
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
class UIView
|
2
|
+
def add_borders(locations, color, width = 1)
|
3
|
+
possible_locations = [:top, :left, :right, :bottom]
|
4
|
+
Array(locations).each do |location|
|
5
|
+
if possible_locations.include?(location)
|
6
|
+
method_call = "add_#{location.to_s}_border"
|
7
|
+
self.send(method_call, color, width)
|
8
|
+
else
|
9
|
+
puts "You must provide a border location in: #{possible_locations}"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
self
|
13
|
+
end
|
14
|
+
alias :add_border :add_borders
|
15
|
+
|
16
|
+
def remove_borders
|
17
|
+
self.layer.sublayers.copy.each do |layer|
|
18
|
+
layer.removeFromSuperlayer
|
19
|
+
end if self.layer.sublayers
|
20
|
+
end
|
21
|
+
alias :remove_border :remove_borders
|
22
|
+
|
23
|
+
def add_top_border(color, width)
|
24
|
+
add_border_with_frame(color, CGRectMake(0, 0, CGRectGetWidth(self.frame), width))
|
25
|
+
end
|
26
|
+
|
27
|
+
def add_right_border(color, width)
|
28
|
+
add_border_with_frame(color, CGRectMake(CGRectGetWidth(self.frame) - width, 0, width, CGRectGetHeight(self.frame)))
|
29
|
+
end
|
30
|
+
|
31
|
+
def add_bottom_border(color, width)
|
32
|
+
add_border_with_frame(color, CGRectMake(0, CGRectGetHeight(self.frame) - width, CGRectGetWidth(self.frame), width))
|
33
|
+
end
|
34
|
+
|
35
|
+
def add_left_border(color, width)
|
36
|
+
add_border_with_frame(color, CGRectMake(0, 0, width, CGRectGetHeight(self.frame)))
|
37
|
+
end
|
38
|
+
|
39
|
+
def add_border_with_frame(color, frame)
|
40
|
+
color = color.CGColor if color.is_a?(UIColor)
|
41
|
+
border = CALayer.layer.tap do |l|
|
42
|
+
l.backgroundColor = color
|
43
|
+
l.frame = frame
|
44
|
+
end
|
45
|
+
self.layer.addSublayer(border)
|
46
|
+
end
|
47
|
+
end
|
metadata
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: OTGHelpers
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.5
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mark Rickert
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-10-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: A set of class extenstions I commonly use in my applications for RubyMotion.
|
28
|
+
email:
|
29
|
+
- mjar81@gmail.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- README.md
|
35
|
+
- lib/OTGHelpers.rb
|
36
|
+
- lib/project/ns_string.rb
|
37
|
+
- lib/project/ui_image.rb
|
38
|
+
- lib/project/ui_label.rb
|
39
|
+
- lib/project/ui_view.rb
|
40
|
+
- lib/project/version.rb
|
41
|
+
homepage: ''
|
42
|
+
licenses:
|
43
|
+
- MIT
|
44
|
+
metadata: {}
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options: []
|
47
|
+
require_paths:
|
48
|
+
- lib
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
requirements: []
|
60
|
+
rubyforge_project:
|
61
|
+
rubygems_version: 2.6.6
|
62
|
+
signing_key:
|
63
|
+
specification_version: 4
|
64
|
+
summary: A set of class extenstions I commonly use in my applications for RubyMotion.
|
65
|
+
test_files: []
|