Position a view in relation to another view using RMQ

91 views Asked by At

I begin today to use RMQ for my RubyMotion project. I read the documentation of the frame / grid system but I cannot find a way to position a view related to another view.

I have 4 UIbuttons with an image inside. I want to place a UILabel under every button centered aligned.

I'm not using grid, i place my button with frame:

  def quiz_button(st)
    st.background_color = color.white
    st.frame = {l: 40, t: 160, w: 120, h: 120}
    st.image_normal = image.resource('sailboat')
    st.image_selected = image.resource('sailboat_selected')
  end

In MotionKit I have "frame below(:username_input, down: 8)"so I can place a view under a specific view, in RMQ I cannot find something that help me to do the same.

1

There are 1 answers

0
Todd Werth On BEST ANSWER

If they are in order (meaning the are siblings of each other and one after the other), you can use below_prev: 8, above_prev, right_of_prev, etc (bp:, ap:, rop: for abbreviations).

To get a specific view, you can use rmq in the normal way: rmq(:username_input).frame.bottom). .frame returns a RubyMotionQuery::Rect instance which has tons of properties such as bottom and right.

So:

st.frame = {l: 40, bp: 8, w: 120, h: 120}

Or

st.frame = {l: 40, t: rmq(:username_input).frame.bottom + 8, w: 120, h: 120}