简体   繁体   中英

UITableViewCell setEditing truncates label

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

在此处输入图片说明

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!

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);
-(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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM