Remove SeparatorInset on iOS 8 UITableView for Xcode 6 iPhone Simulator

后端 未结 15 1921
情深已故
情深已故 2020-11-28 21:40

I found a weird white space on UITableView for iPhone 6 Simulator (iOS 8) on Xcode 6 GM. I have tried to set the SeparatorInset fr

相关标签:
15条回答
  • 2020-11-28 22:34

    In my case in Xcode 6.2, in addition to Will Q's answer, I have to go to Main.storyboard > select the UITableViewCell > Attributes Inspector. Change Separator dropdown list from Default Insets to Custom Insets. Change the left inset from 15 to 0.

    enter image description here

    0 讨论(0)
  • 2020-11-28 22:34

    To make your UITableView separator insets to zero for both iOS7 and iOS8, instead of making a change in the code, make a change in the xib for the UITableView by changing the View->Mode->Aspect Fill.

    0 讨论(0)
  • 2020-11-28 22:35

    Thanks Student for pointing me to the right direction with the comment "Try this self.myTableView.layoutMargins = UIEdgeInsetsZero;" This line of code will only work on iOS 8 because layoutMargins is only available from iOS 8. If I run the same code on iOS 7, it will crash.

    @property(nonatomic) UIEdgeInsets layoutMargins
    Description   The default spacing to use when laying out content in the view.
    Availability  iOS (8.0 and later)
    Declared In   UIView.h
    Reference UIView Class Reference
    

    enter image description here

    Below is the right answer to solve this weird white space by setting the tableview layoutMargins and cell layoutMargins as UIEdgeInsetsZero if it exists (for iOS 8). And it will not crash on iOS 7 as well.

    -(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
    
        if ([tableView respondsToSelector:@selector(setSeparatorInset:)]) {
            [tableView setSeparatorInset:UIEdgeInsetsZero];
        }
    
        if ([tableView respondsToSelector:@selector(setLayoutMargins:)]) {
            [tableView setLayoutMargins:UIEdgeInsetsZero];
        }
    
       if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
            [cell setLayoutMargins:UIEdgeInsetsZero];
       }
    }
    

    See the screen shot below:-

    enter image description here

    0 讨论(0)
提交回复
热议问题