Curnelious
Curnelious

Reputation: 1

autolayout set view to screen size

I have read tutorials about the auto layout but i just couldn't understand the basic things, where they all deals with technical ways to handle Xcode, i couldn't find a simple, clear , explanation to it .

So I will ask 2 basic questions, for 1 problem, a simple problem.

Problem: I have created UIImageView in storyboard, inside a view controller . I would like this view, to always be in the screen size, no matter what iPhone it is .

  1. One way i was thinking about, is just to set it with code, to be in the screen size, this does not works, and in simulator(Xcode 6 - iPhone 6) i see its cover part of the screen.
float width= [UIScreen mainScreen].bounds.size.width;
float height=[UIScreen mainScreen].bounds.size.height;
 self.backImage.frame=CGRectMake( 0,
                                  0
                                     , width, height) ;

Why is this not working(because the image view is checked for auto layout ? )

  1. How to define layouts in storyboard, for this view, to always cover the screen size exactly ?

  2. What if after i set constrains, i would like to set some effect for this view- to move, in code, for example setting the image view size to be 1.5 screen size and centered ?

Upvotes: 0

Views: 3281

Answers (1)

Sander Saelmans
Sander Saelmans

Reputation: 861

Remove any other constraints that define the width or the height of the UIImageView. Open the Pin Tool constraints tab (Interface builder, at the bottom right, third button from the left), and set all the Spacing to nearest neighbour constraints to 0. Now click Apply Constraints, and update your frame.

Upvotes: 2

Related Questions