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当做一条分割线使用,显示效果完美
     
  • 相关阅读:
    Win7旗舰版中的IIS配置asp.net的运行环境
    jquery $(document).ready() 与window.onload的区别
    DEFAULT CURRENT_TIMESTAMP
    存储过程 跳出
    rabbitMQ 重试
    oracle update left join 写法
    error: snap "eclipse" has "install-snap" change in progress
    数据库去空格 去table 去回车符号 去重
    分组 拼接字段
    msyql 去重
  • 原文地址:https://www.cnblogs.com/jiangdaohong/p/4596217.html
Copyright © 2011-2022 走看看