contentView not indenting in iOS 6 UITableViewCell prototype cell

后端 未结 6 2043
醉酒成梦
醉酒成梦 2020-12-02 05:35

I am configuring a custom UITableViewCell using a prototype cell in a Storyboard. However, all the UILabels (and other UI elements) do not seem to

6条回答
  •  粉色の甜心
    2020-12-02 06:02

    Based on the code by Skoota (I am a beginner, don't know much of what you did, but excellent work) my suggestion is to put all your stuff in an edge-to-edge container view and add the following:

    In the cell's header file, I have the following IBOutlets:

    @property (weak, nonatomic) IBOutlet UIView *container;
    @property (weak, nonatomic) IBOutlet NSLayoutConstraint *leftConstrain;
    @property (weak, nonatomic) IBOutlet NSLayoutConstraint *rightConstrain;
    

    In the implementation file, I have the following in awakeFromNib:

    // Remove the IB added horizontal constraint, as that's effective gainst the cell not the contentView
    [self removeConstraint:self.leftConstrain];
    [self removeConstraint:self.rightConstrain];
    
    // Create a dictionary to represent the view being positioned
    NSDictionary *containerViewDictionary = NSDictionaryOfVariableBindings(_container);
    
    // Create the new left constraint (0 spacing because of the edge-to-edge view 'container')
    NSArray *constraints = [NSLayoutConstraint constraintsWithVisualFormat:@"|-0-[_container]" options:0 metrics:nil views:containerViewDictionary];
    // Add the left constraint against the contentView
    [self.contentView addConstraints:constraints];
    
    // Create the new constraint right (will fix the 'Delete' button as well)
    constraints = [NSLayoutConstraint constraintsWithVisualFormat:@"[_container]-0-|" options:0 metrics:nil views:containerViewDictionary];
    // Add the right constraint against the contentView
    [self.contentView addConstraints:constraints];
    

    Again, the above was made possible by Skoota. Thanks!!! Al credits go to him.

提交回复
热议问题