Remove SeparatorInset on iOS 8 UITableView for Xcode 6 iPhone Simulator

后端 未结 15 1920
情深已故
情深已故 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:21

    If you want to remove the white line, but keep separator inset as it is, just set the cell.backgroundColor to the tableView backgroundColor. Just setting the cell.contentView.backgroundColor does not make the problem disappear.

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

    Add startup images for iPhone 6 and Plus. Before the images are added the phone is running in scaling mode, i.e. older Apps get scaled to fit the new screen sizes. This may be causing the lines. The new images are Retina HD 5.5 (iPhone6Plus) 1242x2208 and Retina HD 4.7 (iPhone6) 750x1334.

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

    I've tried many ways, none of them work but this one works for me.

     WORK FOR ME

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

    for iOS 8

    try by setting cell.layoutMargins = UIEdgeInsetsZero; in cellForRowAtIndexPath method

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

    My solution with just three lines of code:

    -(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)row{
        //
        // ... your code ...
        //
        if ([cell respondsToSelector:@selector(preservesSuperviewLayoutMargins)]){
            cell.layoutMargins = UIEdgeInsetsZero;
            cell.preservesSuperviewLayoutMargins = false;
        }
        return cell;
    }
    
    0 讨论(0)
  • 2020-11-28 22:34

    IOS8 introduce a new concept named Configuring Content Margins , a new property named layoutMargins is also introduced , for the details of the property , please refer to the Apple Doc . The type of layoutMargins is UIEdgeInsets , by default the value is {8,8,8,8} . To remove the seperator line of TableView in IOS8 , in addition to set tableView.seperatorInset = UIEdgeInsetsZero , you must also do as :

    First define the macro

    #define isIOS8SystemVersion (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_7_1)
    

    In the UITableViewDelegate method add :

        - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
        {
             static NSString *reuseId = @"cellReuseID" ;
             UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseId];
             if(!cell){
                 cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuseId];     
             if(isIOS8SystemVersion){   
                 cell.layoutMargins = UIEdgeInsetsZero;
                 cell.preservesSuperviewLayoutMargins =NO ;
             }
    
        }
    

    Doing these will remove the seperator line . You can also do as follow :

        UITableView *tableView = [[UITableView alloc] init];
        if(isIOS8SystemVersion){
             tableView.layoutMargins = UIEdgeInsetsZero ;
        }
    

    and in the UITableViewDelegate method add :

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
         static NSString *reuseId = @"cellReuseID" ;
         UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseId];
         if(!cell){
             cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuseId];     
         if(isIOS8SystemVersion){   
             cell.layoutMargins = UIEdgeInsetsZero;
         }
    }
    
    0 讨论(0)
提交回复
热议问题