当我滑动删除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
通过在现有代码上添加约束或更改现有代码来解决此问题?
提前致谢!