LoginSignup
3
3

More than 5 years have passed since last update.

sugarcubeでREPLからviewを弄る

Posted at

sugarcubeなるgemはその名の通りself.view << subviewのように構文糖衣を提供してくれるのがメインの機能。
これはこれで便利だし面白いのだけど、REPLからviewを簡単に弄ることができるようになる機能も提供されていて、こちらのほうが面白い。

インストール

普通にインストール。

gem install sugarcube
Rakefile
require 'sugarcube'

使う前の準備

app_delegate.rbの先頭に下記を追加だけで完了。

app_delegate.rb
include SugarCube::Adjust

使い方

適当に画面を作って実行。

画面

REPLからtreeコマンドを実行するとviewの階層が取得でき、それぞれに番号が振られている。

(main)> tree
  0: . UIWindow(#114835968, {{0, 0}, {320, 480}})
  1: `-- UIView(#115775792, {{0, 20}, {320, 460}})
  2:     `-- UIRoundedRectButton(#115779232, {{100, 100}, {100, 100}})
  3:         `-- UIButtonLabel(#115781312, {{32, 40}, {36, 19}})
=> UIWindow(#114835968, [[0.0, 0.0],{320.0 × 480.0}], )

ボタンを弄りたいので2番を指定し下記のように実行。

(main)> b = (a 2)
=> UIRoundedRectButton(#115779232, [[100.0, 100.0],{100.0 × 100.0}],  child of UIView #115775792)

弄ってみる。

(main)> b.frame = [[0,0],[100,100]]
=> [[0, 0], [100, 100]]

即座に結果が反映される。

調整後の画面

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3