Helpers for RubyMotion
Ruby Shell
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
app
lib
.gitignore
Gemfile
README.md
Rakefile
basic-scaffold.gemspec
build.sh

README.md

BasicScaffold for RubyMotion

A collection of helpers and wrappers used to wrap CocoaTouch code and provide more Ruby-like APIs. BasicScaffold is still in its early development, please don't use in production.

BasicScaffold may use BubbleWrap as dependency.

Why don't you fork/pull request BubbleWrap instead of making your own gem?

Because I make some weird helpers that are useful to me but not necessarily to others.

Installation

In Gemfile

gem 'basic-scaffold', git: 'https://github.com/sehkai/BasicScaffold.git'

Or just copy paste just the code you want to use.

UIStyledText

Style your labels with tags

label = TTTStyledLabel.alloc.initWithFrame [[0, 44], [300, 50]]
label.text = <<-eos
1. ----- ----- ----- <b>bold</b> -----,r\n<f:Helvetica-Bold>Helvetica bold</f> ----- 
<c:#ff0000>color</c> ----- -----, ----- ----- ----- <h:20.0>height at 20</h> -----,r\n ----- ----- 
<s:17>size at 17</s> ----, ----- ----- <u>underline</u> --- ----,r\n----- ----- ----- --- ----, 
----- ----- ----- --- ----, ----- ----- ----- --- ---, ----- ----- ----- --- ----, 
----- ----- ----- --- ----, <h:50.0><s:20>size at 20</s></h> ----- ----- --- ----, <c:#ff0000>color red</c> 
----- ----- --- ----, ----- ----- ----- --- ----, ----- ----- ----- --- ----.\n
<a:right><s:11><b>This text is right</b></s></a>
eos
label.adjustHeight = true
label.font = UIFont.systemFontOfSize(20) 
label.lineHeightMultiple = 1.0
label.reloadText

Keyboard, UITextView and UIScrollView

UITextView is a pain because of Keyboard behaviour. It doesn't disappear automatically, and half of the screen becomes unreachable.

To prevent this, add include BasicScaffold::KeyboardNotifications to your ViewController.

include BasicScaffold::KeyboardNotificationsViewController
self.keyboardScrollView = @scrollView # (if necessary)
self.keyboardTabBar = self.parentViewController.tabBarController.tabBar # (if necessary)
# /!\ Be sure you implement both viewWillAppear and viewWillDisappear

setHeight/Width/X/Y

before

frame = @view.frame
frame.size.height = 50
@view.frame = frame

after

@view.height = 50

more advanced

@image.updateFrame center_x: '50%', width: '50%', context: WeakRef.new(self.view)

headset/microphone

BS.headsetPluggedIn?
BS.microphonePluggedIn?

sizeof()

sizeof(CTParagraphStyleSetting.type)
sizeof(CGRect.type)
sizeof(:float)

Hash.deep_symbolize_keys

{"this" => {"is" => {"result" => "of a json"}}}.deep_symbolize_keys
=> {:this=>{:is=>{:result=>"of a json"}}}

styles

UILabel.addStyle :title_label do |label|
  label.backgroundColor = UIColor.blueColor
end

label = UILabel.alloc.initWithFrame frame
label.styleWith :title_label

or use a special sheet (default is :main)

UILabel.addStyle :title_label, :my_sheet do |label|
  label.backgroundColor = UIColor.blueColor
end

label = UILabel.alloc.initWithFrame frame
label.styleWith :title_label, :my_sheet