zoukankan      html  css  js  c++  java
  • UITableView的分割线长短的控制

    UITableView的默认的cell的分割线左边没有顶满,而右边却顶满了。这样显示很难看。我需要让其左右两边都是未顶满状态,距离是20像素

    // code1
        if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
            [self.tableView setSeparatorInset:UIEdgeInsetsMake(0, 20, 0, 20)];
        }
    
    // code2 
        if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) {
            [self.tableView setLayoutMargins:UIEdgeInsetsMake(0, 20, 0, 20)];
        }

    添加UITableView的一个代理方法:

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

    ode1处代码: 
    定制cell分割线的frame

    code2处代码: 
    -layoutMargins returns a set of insets from the edge of the view’s bounds that denote a default spacing for laying out content. 
    If preservesSuperviewLayoutMargins is YES, margins cascade down the view tree, adjusting for geometry offsets, so that setting the left value of layoutMargins on a superview will affect the left value of layoutMargins for subviews positioned close to the left edge of their superview’s bounds 
    If your view subclass uses layoutMargins in its layout or drawing, override -layoutMarginsDidChange in order to refresh your view if the margins change.

  • 相关阅读:
    python3.7.6安装爬虫akshare
    linux执行crotab是python脚本不生效解决方案
    centos7安装smb共享目录
    搜索引擎集群安装7.8-head-ik
    npm更换阿里源
    nginx访问静态文件不下载,修改默认流下载
    jenkins通过证书ssh访问代码解决方法
    redis创建密码
    微信二次分享时缩略图及描述信息丢失
    redis安装使用
  • 原文地址:https://www.cnblogs.com/jukaiit/p/6553502.html
Copyright © 2011-2022 走看看