Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XLFormRowDescriptorTypeTextView long label spills over cell #1047

Open
tiritea opened this issue Apr 3, 2019 · 1 comment
Open

XLFormRowDescriptorTypeTextView long label spills over cell #1047

tiritea opened this issue Apr 3, 2019 · 1 comment

Comments

@tiritea
Copy link

tiritea commented Apr 3, 2019

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?

@tiritea
Copy link
Author

tiritea commented Apr 3, 2019

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]];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant