我想动态调整UITableViewCell内部的UIImage的宽度,我使用情节提要来设计UITableViewCell,我刚刚添加了标签和图片,属性得到正确更新,甚至加载了标签中的宽度以表明它是正确的值,对于该图像,我正在加载要重复的背景图像,但是如果上下滚动图像,图像最初不会更新宽度如预期的那样显示,这是cellForRowAtIndexPath的代码,我也尝试将代码放在willDisplayCell方法上,结果相同
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"mycustomcell"];
int r = [[data objectAtIndex:indexPath.row] intValue];
UIImageView *img = (UIImageView *)[cell viewWithTag:2];
img.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"some_img" ofType:@"png"]]];
CGRect frame = img.frame;
frame.size.width = r*16;
img.frame = frame;
int n = img.frame.size.width;
UILabel *label = (UILabel *)[cell viewWithTag:1];
label.text = [NSString stringWithFormat:@"custom %d", n];
[cell setNeedsDisplay];
return cell;
}
我只是想让它最初在滚动后起作用,想法?
嗯,删除“自动版式”可以解决此问题
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句