我有一个使用页面控件的 UIscrollView。我正在代码中将表格添加到 ScrollView 中。表格 View 每边应有 20 像素的填充。所以我执行以下操作。
CGRect frame = self.scrollView.bounds;
frame.size.width = 280.0f;
frame.size.height = self.scrollView.bounds.size.height;
frame.origin.x = (320 * page)+20;
NSLog(@"orgin x is %d",(320 * page)+20);
NSLog(@"orgin x is %f",frame.origin.x);
frame.origin.y = 0;
UITableView *tableStage = [[UITableView alloc]initWithFrame:frame];
tableStage.backgroundColor = [UIColor colorWithRed:(250/255.0) green:(248/255.0) blue:(247/255.0) alpha:100];
tableStage.delegate = self;
tableStage.dataSource = self;
tableStage.tag = page;
tableStage.contentMode = UIViewContentModeScaleAspectFit;
[self.scrollView addSubview:tableStage];
[self.pageViews replaceObjectAtIndex:page withObject:tableStage];
但是我得到了以下结果。
就像你可以看到的,下一个表格 View 总是向左移动更多的东西。知道如何解决这个问题吗?
最佳答案
试试这个
CGRect frame = self.scrollView.bounds;
float offset=20;
frame.size.width = frame.size.width-(2*offset);
frame.origin.x = (320 * page)+offset;
frame.origin.y = 0;
UITableView *tableStage = [[UITableView alloc]initWithFrame:frame];
不需要这一行
tableStage.contentMode = UIViewContentModeScaleAspectFit;
关于iphone - UITableview 未正确放置在 uiscrollview 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16539282/