xmartlabs/XLForm

XLFormRowDescriptorTypeTextView long label spills over cell

tiritea opened this issue · 1 comments

code:

            row = [XLFormRowDescriptor formRowDescriptorWithTag:tag rowType:XLFormRowDescriptorTypeTextView title:title];
            [row.cellConfig setObject:UIColor.grayColor forKey:@"textView.textColor"];
            [row.cellConfig setObject:UIColor.redColor forKey:@"textLabel.backgroundColor"]; // HACK

This is the displayed result with very long label:

IMG_0339

Relevant code:

#pragma mark - XLFormDescriptorCell

-(void)configure
{
    [super configure];
    [self setSelectionStyle:UITableViewCellSelectionStyleNone];
    UILabel *textLabel = [UILabel autolayoutView];
    [textLabel setContentHuggingPriority:500 forAxis:UILayoutConstraintAxisHorizontal];
    [self.contentView addSubview:textLabel];
    _textLabel = textLabel;
    
    XLFormTextView *textView = [XLFormTextView autolayoutView];
    [self.contentView addSubview:textView];
    _textView = textView;
    
    [self.textLabel addObserver:self forKeyPath:@"text" options:NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew context:0];
    NSDictionary * views = @{@"label": self.textLabel, @"textView": self.textView};
    [self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-8-[label]" options:0 metrics:0 views:views]];
    [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:self.textView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeTop multiplier:1 constant:0]];
    [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:self.textView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeBottom multiplier:1 constant:0]];
    [self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[textView]-0-|" options:0 metrics:0 views:views]];
}

In the code (above), constraints are specified for the textView to constraint it within the enclosing cell's contentView, but not for the textLabel. So for a very long label, autosizing the cell - ie row.height = UITableViewAutomaticDimension - doesnt work either.

Fix: add similar constraints on the textLabel too?

adding this fix seems to work:

[self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:self.textLabel attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationLessThanOrEqual toItem:self.contentView attribute:NSLayoutAttributeBottom multiplier:1 constant:0]];