如何使用 Objective C iOS 从 Table View in iPhone X 的顶部删除多余的 space
How to remove extra space from the top of the Table View in iPhone X using Objective C iOS
我已经在 Objective C 中开发了一个应用程序,它在所有 iPhone 手机上运行良好。但是,当我在 iPhone X 模拟器中 运行 这个应用程序时,我不知道如何在 UITableView 的顶部获得一些额外的 space (大约 20-22 像素)。我尝试了所有这些解决方案,但下面的 none 帮助了我:
self.tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, self.tableView.bounds.size.width, 0.01f)];
self.edgesForExtendedLayout = UIRectEdgeNone;
[tblProducts setSectionHeaderHeight:0];
self.automaticallyAdjustsScrollViewInsets = NO;
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return CGFLOAT_MIN;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
return CGFLOAT_MIN;
}
我知道这可以通过将我的 table 视图 contentInset 设置为 :
tblProducts.contentInset = UIEdgeInsetsMake(-30, 0, 0, 0);
iPhone X 是否有任何其他解决方案来解决此问题?
我在ViewDidLoad中检查了我的table视图框架,它是(0, 64, WIDTH, HEIGHT),状态栏有问题吗?
请推荐我。提前致谢!
您可以尝试将 contentInsetAdjustmentBehavior
属性 设置为 Never
。
在Swift中,我在UICollectionView
中有这个:
if #available(iOS 11.0, *) {
collectionView.contentInsetAdjustmentBehavior = .never
}
在Objective-C中,同样适用于UITableView
,这样设置:
if (@available(iOS 11.0, *)) {
[_tableView setContentInsetAdjustmentBehavior: UIScrollViewContentInsetAdjustmentNever];
}
如果有人在寻找故事板的答案,那么select故事板中的 UITableView,只需将内容插入更改为从不,如下所示 link
您可以将分组的表格视图样式设置为普通样式,这将删除多余的 space 或者您可以将一个 属性 设置为您的 Viewcontroller is
self.extendedLayoutIncludesOpaqueBars = 真
我已经在 Objective C 中开发了一个应用程序,它在所有 iPhone 手机上运行良好。但是,当我在 iPhone X 模拟器中 运行 这个应用程序时,我不知道如何在 UITableView 的顶部获得一些额外的 space (大约 20-22 像素)。我尝试了所有这些解决方案,但下面的 none 帮助了我:
self.tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, self.tableView.bounds.size.width, 0.01f)];
self.edgesForExtendedLayout = UIRectEdgeNone;
[tblProducts setSectionHeaderHeight:0];
self.automaticallyAdjustsScrollViewInsets = NO;
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return CGFLOAT_MIN;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
return CGFLOAT_MIN;
}
我知道这可以通过将我的 table 视图 contentInset 设置为 :
tblProducts.contentInset = UIEdgeInsetsMake(-30, 0, 0, 0);
iPhone X 是否有任何其他解决方案来解决此问题?
我在ViewDidLoad中检查了我的table视图框架,它是(0, 64, WIDTH, HEIGHT),状态栏有问题吗?
请推荐我。提前致谢!
您可以尝试将 contentInsetAdjustmentBehavior
属性 设置为 Never
。
在Swift中,我在UICollectionView
中有这个:
if #available(iOS 11.0, *) {
collectionView.contentInsetAdjustmentBehavior = .never
}
在Objective-C中,同样适用于UITableView
,这样设置:
if (@available(iOS 11.0, *)) {
[_tableView setContentInsetAdjustmentBehavior: UIScrollViewContentInsetAdjustmentNever];
}
如果有人在寻找故事板的答案,那么select故事板中的 UITableView,只需将内容插入更改为从不,如下所示 link
您可以将分组的表格视图样式设置为普通样式,这将删除多余的 space 或者您可以将一个 属性 设置为您的 Viewcontroller is
self.extendedLayoutIncludesOpaqueBars = 真