D
D
deleted-mezhevikin2013-10-17 17:26:27
iOS
deleted-mezhevikin, 2013-10-17 17:26:27

How to push UIView to the bottom of parent view using NSLayoutConstraint?

1d12e066b822573117cb563ebaf145bf.png
There is a UIView (blue in the picture) with a fixed height of 45px, you need to press it to the bottom using autolayout (NSLayoutConstraint).
It turned out to press UIButton in this way, but it is not clear how to do it with view.
ps is interested in the implementation of the code without InterfaceBulder
Tried like this:

CGRect frame = CGRectMake(0, 500, self.view.frame.size.width, 45);
UIView *bottom = ;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Storozhev, 2013-10-17
@deleted-mezhevikin

I prefer to use Visual Format Language

    NSArray *verticalConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"V:[view(height)]-|"
                                                                           options:0
                                                                           metrics:@{
                                                                               @"height" : @(50)
                                                                           }
                                                                             views:@{
                                                                                 @"view" : view
                                                                             }];

    NSArray *horizontalConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0-[view]-0-|"
                                                                             options:0
                                                                             metrics:nil
                                                                               views:@{
                                                                                   @"view" : view
                                                                               }];
    [self.view addConstraints:verticalConstraints];
    [self.view addConstraints:horizontalConstraints];

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question