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 <lutherba...@gmail.com>
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 (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to