我正在尝试更改自定义UITableViewCell中包含的UILabel的位置,但它不会移动。我启用了自动布局。
- (void)updateLayout
{
NSArray* comp = [self.accessibilityHint componentsSeparatedByString:@"/"];
if (comp.count > 1)
{
CGRect rect = _imageViewT.frame;
rect.origin.x = 20 * comp.count;
rect.size.width = 44.0;
[_imageViewT setFrame:rect];
[_imageConstraint setConstant:_imageViewT.frame.origin.x-8];
rect = _lableT.frame;
rect.origin.x = _imageViewT.frame.size.width+_imageViewT.frame.origin.x+8;
rect.size.width = self.frame.size.width-rect.origin.x-40;
[_lableT setFrame:rect];
//[_imageConstraint setConstant:_imageViewT.frame.origin.x-8];
}
else
{
CGRect rect = _imageViewT.frame;
rect.origin.x = 10;
rect.size.width = 43.0;
[_imageViewT setFrame:rect];
[_imageConstraint setConstant:2];
rect = _lableT.frame;
rect.origin.x = 62;
rect.size.width = self.frame.size.width-rect.origin.x-40;
[_lableT setFrame:rect];
}
}
我从cellForRowAtIndexPath调用update方法。 self.accessibilityHint包含字符串,如aa / bb / cc,aa / cc
答案 0 :(得分:1)
UITableViewCell将在layoutSubviews:
之后在 cellForRowAtIndexPath:
中布置子视图,因此您的布局将在单元格的layoutSubviews中重置。
您应该将布局代码从cellForRowAtIndexPath:移动到单元格的layoutSubviews。
答案 1 :(得分:0)
设置label的autoresizingMask属性,我总是将它与单元格的子视图一起使用。