17

Is there any way to move a group of views within another without grouping all in the center?

Edit: Here some images with the process.

1.- I have a view with separate subviews (labels, buttons, images...) enter image description here

2.- I create a new view (that will contain all the subviews) enter image description here

3.- Select all the subviews and put them in the new super view. enter image description here

4.- When the subviews are in the new "super"view, all of them are centered and I need to relocate all. enter image description here

Mazyod
  • 22,319
  • 10
  • 92
  • 157
alejandromp
  • 929
  • 1
  • 10
  • 19

2 Answers2

33

I found a very nifty solution that you are not gonna believe .. !

I had a group of like 30 labels and buttons positioned pixel by pixel, so I HAD to, no matter what, move them while preserving their relative locations to each other.. Here is what I did:

  1. Select all the views (labels, button, ... etc)
  2. Editor -> Embed In -> View. (Now, they are in a view)
  3. Move that view wherever you like. (Heck, you can even cut and paste it to a new NIB!)
  4. Selected the view, Editor -> Unembed ! :D

I haven't read this anywhere, I came up with it yesterday .. Am 100% sure people somewhere have found this way before me, though.

EDIT:

It seems Xcode 4.5 renders this answer obsolete. Copy/Pasting a bunch of views now retains their relative locations to each other. Don't bother with this if you grew a habit on using it!

Actually, I think this answer is still viable!

Mazyod
  • 22,319
  • 10
  • 92
  • 157
0

enter image description here

You can make one view except xib's main view add that view contain all imageview,label in this view like below image. Assign IBoutlet to the the ViewInvoiceNumber and when set frame add subviews will move according that view like group.. But you have to enter all label,button,image view as subview of that view..

Hope, this will help you...

Nitin
  • 7,455
  • 2
  • 32
  • 51
  • So it must be done by code. There is no way to do in IB. The problem is that if I try to move a group of separate views into a view (to group them all) the separates views align all to the center in IB. so I need to relocate them again. This happen a lot when you need to change some view and you need to have all views in the same group to change somthing by code just one time, within the requeirment to do that code for each view. – alejandromp Apr 28 '12 at 12:05
  • As shown image you can make group in IB and and when set the move main view all are move like group. I suggest to you to ask your question clearly. So someone can help you or give you right and... – Nitin Apr 28 '12 at 12:09