1

UITableCellサブクラスを削除するためにスワイプすると、この奇妙なサイズ変更が発生します ( ExpenseCell):

スクリーンショット

UILabels内容に応じてサイズを変更するために使用するコードを次に示します。

-(void)layoutSubviews{
    [super layoutSubviews];

    NSInteger leftMargin = 0;

    if (![descriptionLabel.text isEqualToString:@""]){
        leftMargin = 15;
    }

    CGSize descriptionLabelSize = [descriptionLabel.text sizeWithFont:descriptionLabel.font];
    CGRect descriptionLabelRect = CGRectMake(descriptionLabel.frame.origin.x,
                                         descriptionLabel.frame.origin.y,
                                         descriptionLabelSize.width,
                                         descriptionLabelSize.height);
    descriptionLabel.frame = descriptionLabelRect;

    CGSize categoryLabelSize = [categoryLabel.text sizeWithFont:categoryLabel.font];
    CGRect categoryLabelRect = CGRectMake(descriptionLabel.frame.origin.x + descriptionLabel.frame.size.width + leftMargin,
                                      categoryLabel.frame.origin.y,
                                      categoryLabelSize.width,
                                      categoryLabelSize.height);
    categoryLabel.frame = categoryLabelRect;
}

上記のコードにコメントすると、この問題はありませんが、 autoresizing が失われましたUILabels

制約を追加するAutoLayoutか、既存のコードを変更することで、これを修正する方法を知っていますか?

前もって感謝します!

4

0 に答える 0