• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Retina and VFL vs Programmatic Layout
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Retina and VFL vs Programmatic Layout


  • Subject: Re: Retina and VFL vs Programmatic Layout
  • From: Luther Baker <email@hidden>
  • Date: Sat, 26 Jul 2014 11:11:38 -0500

Ah, I forgot to add constraints to establish the origin.

Got it. Thanks,
-Luther



On Sat, Jul 26, 2014 at 10:44 AM, Luther Baker <email@hidden>
wrote:

> In the following example, I'm displaying a child view in a container view
> attached to a view controller's view property ... on a Retina iPhone
> simulator.
>
> EXPECTED: The VFL constraints cause the child to fill the screen whereas
>
> UNEXPECTED: the programmatic constraints cause the child to fill exactly
> 1/4 of the screen (1/2 width, 1/2 height). The programmatic constraints
> work if I set the multiplier=2.0 on each of those constraints.
>
> I normally don't use width / height constraints this way but I'm surprised
> by the outcome. Is this a Retina pixels/points thing or am I doing
> something wrong?
>
> Thanks,
> -Luther
>
>
> //
> // 1. Fill the parent view with a simple, yellow container
> //
>     _containerView = [[UIView alloc] init];
>     _containerView.backgroundColor = [UIColor yellowColor];
>     _containerView.translatesAutoresizingMaskIntoConstraints = NO;
>     [self.view addSubview:_containerView];
>
>     NSArray *cc = [NSLayoutConstraint constraintsWithVisualFormat:@
> "V:|[container]|"
>
> options:NSLayoutFormatAlignAllCenterX
>                                                           metrics:nil
>                                                             views:@{
> @"container" : _containerView }];
>     [self.view addConstraints:cc];
>     cc = [NSLayoutConstraint constraintsWithVisualFormat:@
> "H:|[container]|"
>
> options:NSLayoutFormatAlignAllCenterY
>                                                  metrics:nil
>                                                    views:@{ @"container"
> : _containerView }];
>     [self.view addConstraints:cc];
>
> //
> // 2. Add a red child to the aforementioned container view
> //
>
>     UIView *childView = [[UIView alloc] init];
>     childView.backgroundColor = [UIColor redColor];
>     childView.translatesAutoresizingMaskIntoConstraints = NO;
>     [_containerView addSubview:childView];
>
> // WORKS AS EXPECTED
>
>     cc = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|[child]|"
>
> options:NSLayoutFormatAlignAllCenterX
>                                                           metrics:nil
>                                                             views:@{
> @"child" : childView }];
>     [_containerView addConstraints:cc];
>     cc = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|[child]|"
>
> options:NSLayoutFormatAlignAllCenterY
>                                                  metrics:nil
>                                                    views:@{ @"child" :
> childView }];
>     [_containerView addConstraints:cc];
>
> //
> // now, replace the VFL from above with this and the child view only fills
> 1/4 of the screen
> //
>
>     NSLayoutConstraint *c = [NSLayoutConstraint
> constraintWithItem:childView
>
> attribute:NSLayoutAttributeWidth
>
> relatedBy:NSLayoutRelationEqual
>
> toItem:_containerView
>
> attribute:NSLayoutAttributeWidth
>                                                         multiplier:1.0
>                                                           constant:0.0];
>     [_containerView addConstraint:c];
>
>     c = [NSLayoutConstraint constraintWithItem:childView
>                                      attribute:NSLayoutAttributeHeight
>                                      relatedBy:NSLayoutRelationEqual
>                                         toItem:_containerView
>                                      attribute:NSLayoutAttributeHeight
>                                     multiplier:1.0
>                                       constant:0.0];
>     [_containerView addConstraint:c];
>
>
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


References: 
 >Retina and VFL vs Programmatic Layout (From: Luther Baker <email@hidden>)

  • Prev by Date: Retina and VFL vs Programmatic Layout
  • Next by Date: 10.10 NSSlider continuous mode sends gazillions of action messages
  • Previous by thread: Retina and VFL vs Programmatic Layout
  • Next by thread: 10.10 NSSlider continuous mode sends gazillions of action messages
  • Index(es):
    • Date
    • Thread