chandu
chandu

Reputation: 57

Using Auto Layouts while 4 screen app running in 3.5 screen

I developed a app for iPhone5 i enabled Use Auto Layouts.I have taken vertical space 40 for each button to its another button . when i run this app on iPhone4s the last button is not appeared.I.How to decrease vertical spacing while it is running in 4s.enter image description here

This is how it looks in iphone 4s

Upvotes: 2

Views: 433

Answers (3)

Rob
Rob

Reputation: 438232

While you can use clear/hidden UIView objects as spacers, as others have described, that's not necessary. You can also create constraints programmatically, evenly spacing them with the judicious use of multiplier values supplied to the constraintWithItem method. For example, if you have an array of UIButton objects, you can vertically space them with:

[buttons enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:obj
                                                          attribute:NSLayoutAttributeCenterY
                                                          relatedBy:NSLayoutRelationEqual
                                                             toItem:self.view
                                                          attribute:NSLayoutAttributeCenterY
                                                         multiplier:2.0 * (idx + 1.0)/([buttons count] + 1.0)
                                                           constant:0.0]];
}];

Upvotes: 0

Mike Weller
Mike Weller

Reputation: 45598

If you don't want to do this in code, you have to add some hidden "spacer" views in between your buttons with "equal height" constraints and no explicit height. They will expand/contract as appropriate to space the buttons out correctly.

enter image description here

Upvotes: 2

Fogmeister
Fogmeister

Reputation: 77661

You need to use a spacer view between each button. That way you can use a variable size of the space that depends on the height of the screen.

Something like this...

@"V:|[_spacer1][_button1][_spacer2(==_spacer1)][_button2][_spacer3(==spacer1)][_button3]...[_lastSpacer(==spacer1)]|"

This will then layout all the buttons with equal spaces between them. But the space between will change depending on the height of the screen.

Upvotes: 2

Related Questions