zoukankan      html  css  js  c++  java
  • 自定义UITableView的Seperator

    在默认配置中 ,UITableView的Cell之间的Seperator左边总是空出一块,即使在Storyboard中设置为0 ,也没有效果

    需要在代码中进行配置,在ViewController中实现如下方法

    -(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath

    {

        // Remove seperator inset

        if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {

            [cell setSeparatorInset:UIEdgeInsetsZero];

        }

        

        // Prevent the cell from inheriting the Table View's margin settings

        if ([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) {

            [cell setPreservesSuperviewLayoutMargins:NO];

        }

        

        // Explictly set your cell's layout margins

        if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {

            [cell setLayoutMargins:UIEdgeInsetsZero];

        }

    }

    如果所有的界面都是如此风格,也可以通过UIAppearance 统一配置

    // iOS 7:

    [[UITableView appearance] setSeparatorStyle:UITableViewCellSeparatorStyleSingleLine];

    [[UITableView appearance] setSeparatorInset:UIEdgeInsetsZero];

     

    [[UITableViewCell appearance] setSeparatorInset:UIEdgeInsetsZero];

     

    // iOS 8:

    if ([UITableView instancesRespondToSelector:@selector(setLayoutMargins:)]) {

        [[UITableView appearance] setLayoutMargins:UIEdgeInsetsZero];

        [[UITableViewCell appearance] setLayoutMargins:UIEdgeInsetsZero];

        [[UITableViewCell appearance] setPreservesSuperviewLayoutMargins:NO]; 

    }

    原文链接:http://stackoverflow.com/questions/25770119/ios-8-uitableview-separator-inset-0-not-working

  • 相关阅读:
    python-44-初识队列
    python-43-进程锁/信号量/事件
    python-42-Process多进程
    python-41-初识hmac与socketserver模块
    python-40-初识socket与struct
    python-39-hashlib与logging模块
    python-38-用于面向对象的内置函数
    python-37-各种反射
    python-36-封装与面向对象函数
    python-35-多态与初识封装
  • 原文地址:https://www.cnblogs.com/taojigu/p/5063736.html
Copyright © 2011-2022 走看看