Вопрос

I'm trying to animate the content of a custom UITableViewCell by moving a label to the right to create space for the red delete icon. The movement works fine but the whole text gets truncated, which it isn't supposed to, there is no reason to me why it does that because there is enough space. This is what it looks like in the edit state

enter image description here

This is my code

-(void)setEditing:(BOOL)editing animated:(BOOL)animated {
    [super setEditing:editing animated:animated];

    if (editing) {
        self.image.alpha = 0.0;
        self.textLabel.frame = CGRectMake(15, 0, 30, 44);
    } else {
        self.image.alpha = 1.0;
        self.textLabel.frame = CGRectMake(10, 0, 30, 44);
    }
}

What am I doing wrong here? Thank you very much!

Это было полезно?

Решение 2

-(void)setEditing:(BOOL)editing animated:(BOOL)animated {
    [super setEditing:editing animated:animated];

    CGRect frame = CGRectZero;

    if (editing) {
        self.image.alpha = 0.0;
        frame.origin = CGPointMake(15, 0);

    } else {
        self.image.alpha = 1.0;
        frame.origin = CGPointMake(10, 0);
    }

    frame.size = [self.textLabel.text sizeWithFont:self.textLabel.font];
    self.textLabel.frame = frame;
}

Другие советы

Try using this :

self.textLabel.numberOfLines = 0;
[self.textLabel sizeToFit];

Or you can try this :

self.textLabel.center = CGPointMake(self.textLabel.center.x + 5, self.textLabel.center.y);

Or you can try this :

self.textLabel.frame = CGRectMake(self.textLabel.origin.x + 5, self.textLabel.origin.y, self.textLabel.bounds.size.width, self.textLabel.bounds.size.height);

Or you can try this :

CGSize textSize = [self.textLabel.text sizeWithFont:self.textLabel.font constrainedToSize:self.textLabel.bounds.size lineBreakMode:self.textLabel.lineBreakMode];
self.textLabel.frame = CGRectMake(self.textLabel.origin.x + 5, self.textLabel.origin.y, self.textLabel.bounds.size.width, textSize.height);
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top