Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

erdinc27

macrumors regular
Original poster
Jul 20, 2011
168
1
hey all. i want to use Auto Layout for the first time in my project. but i am facing with a problem. i have 6 buttons next to each other and i want to align them horizontally centered in both landscape and portrait orientations. it is done in portrait but i have problem in landscape mode. here a screenshot how it looks in both modes. so how i can do same thing in landscape mode also ?

landscape mode : http://img69.imageshack.us/img69/8995/g6q.png

portrait mode : http://img560.imageshack.us/img560/4865/qu2u.png

so how i can use Auto Layout for that purpose ?
 

erdinc27

macrumors regular
Original poster
Jul 20, 2011
168
1
How have you setup the constraints for each button?

Edit: Wait - I seem to have miss understood you.

You're asking how to do it and not why it's not working?

Have a read here on auto layout:

http://www.raywenderlich.com/20881/beginning-auto-layout-part-1-of-2

Read both parts and you will be able to solve this issue easily in your app.

thanks for the reply. i saw that article before. i tried to apply the examples there but it didnt work. i will try it again.
 

erdinc27

macrumors regular
Original poster
Jul 20, 2011
168
1
thanks for the help. i found such a solution.
ViewController.h
Code:
@property (retain, nonatomic) IBOutlet NSLayoutConstraint *leadLayout;

ViewController.m
Code:
- (void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    
    if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
    {
        self.leadLayout.constant = 124.0 ;
    }
    else if (toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
        self.leadLayout.constant = 52.0 ;
        
}
and between buttons i put Horizontal Spacing Constraint. now it works good.
i make the examples run in the link u sent to me.
 

waterskier2007

macrumors 68000
Jun 19, 2007
1,871
228
Novi, MI
I know you got it working, but why not just align the two middle ones (with an offset from the horizontal center) and then put constraints on the horizontal spacing for the rest of them
 

erdinc27

macrumors regular
Original poster
Jul 20, 2011
168
1
I know you got it working, but why not just align the two middle ones (with an offset from the horizontal center) and then put constraints on the horizontal spacing for the rest of them

actually i thought it in theory but i couldnt make it work in xcode. although the code that i wrote down is working i am still work on the idea that u told. i want to make it work also. i appreciate if u can show how to do it
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.