Matching left alignment of custom & standard UITableViewCell types

前端 未结 5 2221
清歌不尽
清歌不尽 2020-12-23 17:11

I\'m defining custom UITableViewCells in a storyboard. I\'m also using some of the built in standard style cells. I need to set up constraints so that my

5条回答
  •  臣服心动
    2020-12-23 17:49

    What worked for me was adding these 2 lines to my custom UITableViewCell implementation:

    self.preservesSuperviewLayoutMargins = YES;
    self.contentView.preservesSuperviewLayoutMargins = YES;
    // ... add test view to content view...
    

    Then I used Auto Layout with the default spacing:

    [self.contentView addConstraints:[NSLayoutConstraint 
      constraintsWithVisualFormat:@"H:|-[testView]-|" options:0 metrics:nil 
       views:@{@"testView":testLabel}]];
    
    [self.contentView addConstraints:[NSLayoutConstraint 
      constraintsWithVisualFormat:@"V:|-[testView]-|" options:0 metrics:nil 
       views:@{@"testView":testLabel}]];
    

提交回复
热议问题