zoukankan      html  css  js  c++  java
  • UITableViewCell里面separator的设置

    最近cell显示的时候左边一直有15个像素的偏移,查了下面的方法
    //1. 不管用
    [self.tableView setSeparatorInset:UIEdgeInsetsZero];
    // 2.效果不明显,并不能完全从第一个像素显示分割线
     1 - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
     2     if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)])
     3     {
     4         [self.tableView setSeparatorInset:UIEdgeInsetsZero];
     5     }
     6     if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)])
     7     {
     8         [self.tableView setLayoutMargins:UIEdgeInsetsZero];
     9     }
    10 }
    // 3.重写drawRect方法,有效果,颜色设置方便,但是操作cell,会增加手机负担
     1 - (void)drawRect:(CGRect)rect {
     2     CGContextRef context = UIGraphicsGetCurrentContext();
     3     CGContextSetFillColorWithColor(context, [UIColor clearColor].CGColor);
     4     CGContextFillRect(context, rect);
     5    
     6     //上分割线
     7     CGContextSetStrokeColorWithColor(context,[UIColor whiteColor].CGColor);
     8     CGContextStrokeRect(context,CGRectMake(0,0,rect.size.width,1));
     9    
    10     //下分割线
    11     CGContextSetStrokeColorWithColor(context,[UIColor whiteColor].CGColor);
    12     CGContextStrokeRect(context,CGRectMake(0,rect.size.height-1,rect.size.width,1));
    13 }
    // 4.自定义cell,隐藏cell的separator的颜色,然后在cell的separator位置上添加一个只有1像素的view,设置view的颜色,即把view当做一条分割线使用,显示效果完美
     
  • 相关阅读:
    Long类型在前端丢失精度
    Spring Event事件通知
    el-drawer去除自带黑色边框、允许滚动
    XSS攻击
    入门1:nodejs类比Java中:JVM
    https的crt和key证书
    C#如何定制Excel界面并实现与数据库交互
    数据库选型、Oracle 、Mysql、Redis、MSSQL、Access和国产数据库
    写代码同写文章一样
    操作笔记
  • 原文地址:https://www.cnblogs.com/jiangdaohong/p/4596217.html
Copyright © 2011-2022 走看看