Note that there are some explanatory texts on larger screens.

plurals
  1. POAdding NSLayoutConstraint from code
    primarykey
    data
    text
    <p>I am having a lot of problems understanding constraints made in code. I have this container view that is created and set in IB and then in that container NSView's initWithFrame I add the child NSView like this (self is the container view):</p> <pre><code>childView = [[NSView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, tabContainerHeight + tabContainerTopSpace)]; [childView setTranslatesAutoresizingMaskIntoConstraints:NO]; [self addSubview:childView]; NSLayoutConstraint *tabContainerConstraint = [NSLayoutConstraint constraintWithItem:childView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeTop multiplier:1.0f constant:0.0f]; [childView addConstraint:tabContainerConstraint]; tabContainerConstraint = [NSLayoutConstraint constraintWithItem:childView attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeLeading multiplier:1.0f constant:0.0f]; [childView addConstraint:tabContainerConstraint]; tabContainerConstraint = [NSLayoutConstraint constraintWithItem:childView attribute:NSLayoutAttributeTrailing relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeTrailing multiplier:1.0f constant:0.0f]; [childView addConstraint:tabContainerConstraint]; </code></pre> <p>The problem right now is that the child view is not visible at all, I don't know what happens to it. What I want to do is to have the child view to always have its top exactly at the container view's top and the same goes for left and right, so the child view must have a fixed height but always placed at the top of the container view and then stretch to the sides with the container view (like in the attached image if it explains it).</p> <p><img src="https://i.stack.imgur.com/QfBxv.png" alt="enter image description here"></p> <p>How is this done from code?</p> <p>Thank you<br> Søren</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload