我的桌面视图单元格是完全以编程方式创建的(我试图学会从头开始构建应用程序而不使用故事板),单元格的宽度也越来越混乱。UITableViewCell宽度不会动态调整基于iOS设备类型
下面是iPhone 6 Plus中单元格外观的屏幕截图http://imgur.com/ki6txqg。我试图设置单元格,以便单元格中的UIView(self.view)自动调整,以便填充整个屏幕。我不知道为什么宽度保持静态。任何建议将不胜感激。
-(instancetype)initWithTweet:(PCRTweet *)tweet reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super init];
if (self) {
_tweet = tweet;
reuse = reuseIdentifier;
CGSize cellSize = self.contentView.frame.size;
CGRect backgroundView = CGRectMake(10.f, 5.f, (cellSize.width-20.f), (cellSize.height + 90.f));
self.view = [[UIView alloc] initWithFrame:backgroundView];
self.view.backgroundColor = [UIColor whiteColor];
self.view.layer.cornerRadius = 8;
self.view.layer.masksToBounds = YES;
self.view.layer.borderWidth = 1.0f;
self.view.layer.borderColor = background_color_gray.CGColor;
self.view.layer.masksToBounds = NO;
[self.contentView addSubview:self.view];
CGRect picView = CGRectMake(0.f, 0.f, 65.f, 65.f);
self.contentView.backgroundColor = background_color_gray;
}
return self;
}
你在tableview上使用约束吗? –
use self.view.frame.size.width-20.f CGRect backgroundView = CGRectMake(10.f,5.f,(self.view.frame.size.width -20.f),(cellSize.height + 90.f)); –
我建议你修改layourSubviews中的框架或使用约束。 – childrenOurFuture