Programmatically Add CenterX/CenterY Constraints

前端 未结 7 741

I have a UITableViewController that doesn\'t display any sections if there is nothing to show. I\'ve added a label to indicate to the user that there is nothing to display w

相关标签:
7条回答
  • 2020-11-29 18:58

    Programmatically you can do it by adding the following constraints.

    NSLayoutConstraint *constraintHorizontal = [NSLayoutConstraint constraintWithItem:self  
                                                                          attribute:NSLayoutAttributeCenterX 
                                                                          relatedBy:NSLayoutRelationEqual 
                                                                             toItem:self.superview 
                                                                          attribute:attribute 
                                                                         multiplier:1.0f 
                                                                           constant:0.0f];
    
    NSLayoutConstraint *constraintVertical = [NSLayoutConstraint constraintWithItem:self
                                                                            attribute:NSLayoutAttributeCenterY 
                                                                            relatedBy:NSLayoutRelationEqual
                                                                               toItem:self.superview 
                                                                            attribute:attribute 
                                                                           multiplier:1.0f
                                                                             constant:0.0f];
    
    0 讨论(0)
提交回复
热议问题