5

I am trying to create Universal application using iOS storyboard within Xcode 7 and iOS 9. In the storyboard concept I can see lots of methods (autolayout, auto constraints, adaptive UI, etc.). I am confused by those methods of design. Please give me a solution for image view show on center for all iPhone and iPad.

android
  • 453
  • 3
  • 7
  • 14

3 Answers3

5

Its Quite easy ..

1.place the uiimageview to center

Then add the Below constraints

1.centre horizontal to the view && centre vertical to the view

2.set it to aspect ratio

See the image given below. enter image description here

enter image description here

enter image description here

centre horizontal ,centre vertical ,aspect ratio set this three you will get ...

Community
  • 1
  • 1
Kishore Kumar
  • 4,265
  • 3
  • 26
  • 47
2

You can try size classes work with many different screen sizes.

Change constraint like this or other

ArtKorchagin
  • 4,801
  • 13
  • 42
  • 58
klone
  • 39
  • 5
0

If you want to design Universal application in iOS then you must add constraints base on the percentage(%) and There are few situations or cases for which you can not added the constraints from the Starboard but don't wary about that we can do that programatically.

Have you ever try KVConstraintExtensionsMaster library to apply constraints that I have implemented. This library having the method that will update , apply , access and remove the constrains those are applied either applied by Programmatically or from Interface Builder(StoryBoard/xib).

Programmatically imageView show on center for all iPhone and iPad.

- (void)viewDidLoad
{
    [super viewDidLoad];

    /* preparing View Hierarchy */
    UIImageView *imageView = [UIImageView prepareNewViewForAutoLayout];
    [self.view addSubview:imageView];
    [imageView setBackgroundColor:[UIColor blueColor]];

    /* applying constraints */
    [imageView applyConstraintForCenterInSuperview];

    /* Change the Ratio 0.0 to 1.0 to vary the height and width */
    [imageView applyEqualHeightRatioPinConstrainToSuperview:0.8];
    [imageView applyEqualWidthRatioPinConstrainToSuperview:0.8];

    /* Comment the above both RatioPinConstrainToSuperview methods and uncomment below methods and run on both iPhone or iPad and see the magic.*/
    /*
     [imageView applyWidthConstraint:280]; // fixed width for iphone
     [imageView applyHeightConstrain:280]; // fixed height for iphone

     // update width constraint with proper iPad ratio
     [imageView updateAppliedConstraintConstantValueForIpadByAttribute:NSLayoutAttributeWidth];

     // update height constraint with proper iPad ratio
     [imageView updateAppliedConstraintConstantValueForIpadByAttribute:NSLayoutAttributeHeight];
     */
}

From StoryBoard imageView show on center for all iPhone and iPad.

Step 1. Drag and place imageView in view of ViewController.

Step 2. Now Add constraint Horizontal Center in Container and Vertical center in Container.

Step 3. Add constraint Equal Width and Equal Height.

Step 4. Now update multiplier of Equal Width constraint and Equal Height.

keshav vishwkarma
  • 1,832
  • 13
  • 20