iphone - UITableview 未正确放置在 uiscrollview 中

标签 iphone ios objective-c uitableview uiscrollview

我有一个使用页面控件的 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];

但是我得到了以下结果。 enter image description here

就像你可以看到的,下一个表格 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/

相关文章:

iOS Unity Asset Bundle 下载限制 - 粒子效果、动画和动画资源

ios - 如何使用按钮控件进行分页

iphone - 在ios中解析嵌套对象和数组json

iphone - UIPageViewController 在旋转时重置为第一页

iphone - 如何获取NSString的十进制ascii码?

ios - swift :奇怪的向下转型失败

iOS 推送通知 - 角标(Badge)不会显示

ios - 使用 Swift 3 将 iframe 标签(视频)从 html 字符串加载到 Web View 中

ios - CanOpenUrl 方法不适用于 ios 9

iphone - 适用于 iOS 的可视化嵌套树状控件