【问题标题】:How to adjust UITableview margins from left and right programmatically?如何以编程方式从左右调整 UITableview 边距?
【发布时间】:2013-12-05 12:50:22
【问题描述】:

我有一个表格视图(没有表格视图单元格)。我的应用程序在 iOS 6 中运行良好,但是当我在 iOS7 Tableview 中运行它时,边距发生冲突。当我通过代码设置框架时,它的边距仅从左侧和底部调整。我正在使用以下代码

if([[[UIDevice currentDevice]systemVersion]floatValue]>=7){
CGRect newSize = CGRectMake(0,0,730,925);
newSize.origin.y = 0;
newSize.size.width = 728.0;
newSize.size.height = 925.0;
self.myTable.frame = newSize;
}

请给我一些建议,我该如何解决 ? 这是 ios 6 和 ios 7 的图像(它是一个组表视图),我没有更改 ios 7 的任何边距,它与 ios6 中的相同,如果我在 ios 7 中对边距进行任何更改,它也会影响 ios 6 布局。 .

【问题讨论】:

  • 那是什么问题,给我们截图或更清楚地描述您的问题??
  • 你必须设置newSize.origin.y = somevalue;,这样它才能反映双方的变化。
  • @Augustine 我已经上传了快照,请看一下。
  • @MayurShrivas 我试过这个,但它只为左侧设置边距。

标签: ios ipad ios6 ios7


【解决方案1】:

添加自动调整大小属性

//确保启用自动调整大小

self.view.autoresizesSubviews = YES;
myTable = [[myTable alloc]initWithFrame:self.view.bounds];
[myTable setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];
[self.view addSubview:myTable];

【讨论】:

  • 但是如何同时设置左右边距?
猜你喜欢
  • 1970-01-01
  • 2016-09-29
  • 2011-08-26
  • 1970-01-01
  • 2016-10-11
  • 2018-09-12
  • 2011-11-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多