title: how to apply a constraint programmatically to UILabel such that it is 20px above from bottom of the view in Objective C
body: <p>I am implementing autolayout in my app.I want the UILabel to be placed 20px from bottom of the screen by using autolayout programmatically.Please help me out where i am going wrong.With the below code UILabel is getting not displayed on applying bottom constrint.Below is my code.</p>
  
  <pre><code> lblSwipe=[[UILabel alloc]init];
  lblSwipe.text=@"Swipe to learn more";
  lblSwipe.textColor=[UIColor lightGrayColor];
  lblSwipe.textAlignment = NSTextAlignmentCenter;
  lblSwipe.backgroundColor=[UIColor yellowColor];
  lblSwipe.font=[UIFont systemFontOfSize:14.0];
  [self.view addSubview:lblSwipe];
  
  [lblSwipe setTranslatesAutoresizingMaskIntoConstraints:NO];
  
  //to position UILabel in centre of the screen
  NSLayoutConstraint *myConstraint=[NSLayoutConstraint
                                     constraintWithItem:lblSwipe
                                     attribute:NSLayoutAttributeCenterX
                                     relatedBy:NSLayoutRelationEqual
                                     toItem:self.view
                                     attribute:NSLayoutAttributeCenterX
                                     multiplier:1.0
                                     constant:0];
  
  [self.view addConstraint:myConstraint];
  
  //to apply a fixed width of 300 to UILabel
  [lblSwipe addConstraint:[NSLayoutConstraint constraintWithItem:lblSwipe
                                                   attribute:NSLayoutAttributeWidth
                                                   relatedBy:NSLayoutRelationEqual
                                                      toItem:nil
                                                   attribute:NSLayoutAttributeNotAnAttribute
                                                  multiplier:1.0
                                                    constant:300.0]];
  
    //to place UILabel 20px above from bottom of the screen
   [self.view addConstraint:[NSLayoutConstraint constraintWithItem:lblSwipe
                                                       attribute:NSLayoutAttributeBottom
                                                       relatedBy:NSLayoutRelationEqual
                                                          toItem:self.view
                                                       attribute:NSLayoutAttributeBottom
                                                      multiplier:1.0
                                                        constant:20.0]];
  </code></pre>