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当做一条分割线使用,显示效果完美
     
  • 相关阅读:
    pytest知识梳理
    linux服务器时间不同步解决
    python re 多行匹配模式
    nginx--知识梳理
    tomcat--知识梳理
    利用springboot 重定向到静态资源功能,下载一些文件文件
    调试C++代码内存释放,在VS2019控制台显示内存泄露
    C++Primer第五版 第九章 习题9.22
    nginx 配置中间证书
    云苍穹消息推送代码
  • 原文地址:https://www.cnblogs.com/jiangdaohong/p/4596217.html
Copyright © 2011-2022 走看看