Answer the question
In order to leave comments, you need to log in
How to set auto-layout constraints programmatically?
Good afternoon!
I need to superimpose a 250x127 picture on top of everything in the Navigation Controller so that it is always located in the upper right corner.
I'm trying like this:
UIImageView *soldImageView = ;
[self.navigationController.view addSubview:soldImageView];
[self.navigationController.view bringSubviewToFront:soldImageView];
[self.navigationController.view addConstraint:[NSLayoutConstraint constraintWithItem:soldImageView
attribute:NSLayoutAttributeTrailing
relatedBy:NSLayoutRelationEqual
toItem:self.navigationController.view
attribute:NSLayoutAttributeRight
multiplier:1.0
constant:20.0]];
[self.navigationController.view addConstraint:[NSLayoutConstraint constraintWithItem:soldImageView
attribute:NSLayoutAttributeTop
relatedBy:NSLayoutRelationEqual
toItem:self.navigationController.view
attribute:NSLayoutAttributeTop
multiplier:1.0
constant:70.0]];
[self.navigationController.view addConstraint:[NSLayoutConstraint constraintWithItem:soldImageView
attribute:NSLayoutAttributeWidth
relatedBy:NSLayoutRelationEqual
toItem:nil
attribute:NSLayoutAttributeNotAnAttribute
multiplier:1.0
constant:250.0]];
[self.navigationController.view addConstraint:[NSLayoutConstraint constraintWithItem:soldImageView
attribute:NSLayoutAttributeHeight
relatedBy:NSLayoutRelationEqual
toItem:nil
attribute:NSLayoutAttributeNotAnAttribute
multiplier:1.0
constant:127.0]];
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question