问题
I have already developed an app in Objective C which is working fine in all the iPhone mobiles. But when I am running this app in iPhone X Simulator then I dont know how I am getting some extra space (about 20-22 pixels) in the top of the UITableView. I tried all this solutions, but none of the below helped me :
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;
}
I know this can be possible by setting my table view contentInset like :
tblProducts.contentInset = UIEdgeInsetsMake(-30, 0, 0, 0);
Is there any other solution to resolve this issue for iPhone X?
I checked my table view frame in ViewDidLoad, It's (0, 64, WIDTH, HEIGHT), Is there any problem with Status bar?
Please suggest me. Thank you in Advance!
回答1:
You can try setting contentInsetAdjustmentBehavior
property to Never
.
In Swift, I have this in UICollectionView
:
if #available(iOS 11.0, *) {
collectionView.contentInsetAdjustmentBehavior = .never
}
In Objective-C, the same applies to UITableView
, set it like so:
if (@available(iOS 11.0, *)) {
[_tableView setContentInsetAdjustmentBehavior: UIScrollViewContentInsetAdjustmentNever];
}
回答2:
If Anyone is looking for answer with storyboard then select your UITableView in storyboard and just change the content inset to never, like shown in below link
回答3:
You can set tableview style grouped to plain it will remove extra space or you can set one property to your Viewcontroller is
self.extendedLayoutIncludesOpaqueBars = true
来源:https://stackoverflow.com/questions/46639918/how-to-remove-extra-space-from-the-top-of-the-table-view-in-iphone-x-using-objec