IOS TableView&ScrollView


TableView


  • tableView返回headerfooter 不调用,以及滚动不准确

self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
self.tableView.scrollIndicatorInsets = self.tableView.contentInset;
if (@available(iOS 11.0, *)){
self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
self.tableView.estimatedRowHeight = 0;
self.tableView.estimatedSectionHeaderHeight = 0;
self.tableView.estimatedSectionFooterHeight = 0;
}




  • 聊天中tableView插入一条数据后reloadData再滚当到底部后再刷新插入数据的状态
    [self.tableView  reloadData];
        [UIView animateWithDuration:0.2 animations:^{
           [self scrollTableViewToBottomWithAnimuted:NO];
        }];
            [self.tableView  reloadData];

  • tableView删除默认选中行的背景色
[self.tableView deselectRowAtIndexPath:[self.tableView indexPathForSelectedRow]animated:YES];
  • tableView的背景色
 setTableView.backgroundView = [[UIView alloc]init];
    setTableView.backgroundColor = [UIColor redColor];
[UIColor colorWithRed:241.0/255.0 green:241.0/255.0 blue:241.0/255.0 alpha:1];
  • tableViewCell的分割线
setTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  • tableViewCell的分割线颜色
[theTableView setSeparatorColor:[UIColor xxxx ]];
  • tableViewCell选中时背景色
cell.selectedBackgroundView = [[[UIView alloc] initWithFrame:cell.frame] autorelease];

cell.selectedBackgroundView.backgroundColor = [UIColor xxxxxx]; 
  • tableViewCell选中时背景
cell.selectedBackgroundView = [[[UIImageView alloc] initWithImage:[UIIma`ge imageNamed:@"cellart.png"]] autorelease];  还有字体颜色   cell.textLabel.highlightedTextColor = [UIColor xxxcolor];  [cell.textLabel setTextColor:co

-设置tableViewCell的背景颜色

- (void)tableView: (UITableView*)tableView willDisplayCell: (UITableViewCell*)cell forRowAtIndexPath: (NSIndexPath*)indexPath
{
    cell.backgroundColor = indexPath.row % 2?[UIColor colorWithRed: 240.0/255 green: 240.0/255 blue: 240.0/255 alpha: 1.0]: [UIColor whiteColor];
    cell.textLabel.backgroundColor = [UIColor clearColor];
    cell.detailTextLabel.backgroundColor = [UIColor clearColor];
}
  • tableView与tableVieCelll的圆角效果
yourTableView.layer.cornerRadius = 20;


if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7){
        UIView *cellBackgroundView = [[UIView alloc] init];
        //cellBackgroundView.layer.cornerRadius = 8.0;//是否加圆角
        cellBackgroundView.layer.borderWidth = 0.57;//边框宽度
        cellBackgroundView.layer.borderColor = [UIColor colorWithRed:0.92 green:0.92 blue:0.92 alpha:1.0].CGColor;
        cell.backgroundView = cellBackgroundView;
        
    }
  • tableViewGroup没有数据是不显示cell的

  • 在cell里面定义一个view把view的背景设为tableView的背景色,这样就出现间隔了

UIView *view = [[UIView alloc initWithFrame:CGRectMake(0, 0, 320, 10)];
 view.backgroundColor = [UIColor colorWithRed:74.0/255 green:56.0/255 blue:58.0/255 alpha:1.0];
 [cell.contentView addSubview:view];
 [view release];
  • tableView内容重复
 NSArray*subviews = [[NSArray alloc]initWithArray:cell.contentView.subviews];
    for (UIView *subview in subviews) {
        [subview removeFromSuperview];
       
    }
  • 可以用group类型,height Header返回0.0001可以没有header

  • 界面设置
    这里写图片描述

    setTableView= [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, self.view.frame.size.height) style:UITableViewStyleGrouped];
    setTableView.separatorStyle = UITableViewCellSeparatorStyleNone;

  • (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 44;
    }

  • (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 0||section == 3) {
    return 2;
    }
    return 1;
    }

  • ios7风格是顶到左右,加下面的方法和一避免CGRect bounds 调可以让cell的线超左右

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([cell respondsToSelector:@selector(tintColor)]) {
        if (tableView == self.tableView) {
            CGFloat cornerRadius = 5.f;
            cell.backgroundColor = UIColor.clearColor;
            CAShapeLayer *layer = [[CAShapeLayer alloc] init];
            CGMutablePathRef pathRef = CGPathCreateMutable();
            CGRect bounds = CGRectInset(cell.bounds, 10, 0);
            BOOL addLine = NO;
            if (indexPath.row == 0 && indexPath.row == [tableView numberOfRowsInSection:indexPath.section]-1) {
                CGPathAddRoundedRect(pathRef, nil, bounds, cornerRadius, cornerRadius);
            } else if (indexPath.row == 0) {
                CGPathMoveToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMaxY(bounds));
                CGPathAddArcToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMinY(bounds), CGRectGetMidX(bounds), CGRectGetMinY(bounds), cornerRadius);
                CGPathAddArcToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMinY(bounds), CGRectGetMaxX(bounds), CGRectGetMidY(bounds), cornerRadius);
                CGPathAddLineToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMaxY(bounds));
                addLine = YES;
            } else if (indexPath.row == [tableView numberOfRowsInSection:indexPath.section]-1) {
                CGPathMoveToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMinY(bounds));
                CGPathAddArcToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMaxY(bounds), CGRectGetMidX(bounds), CGRectGetMaxY(bounds), cornerRadius);
                CGPathAddArcToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMaxY(bounds), CGRectGetMaxX(bounds), CGRectGetMidY(bounds), cornerRadius);
                CGPathAddLineToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMinY(bounds));
            } else {
                CGPathAddRect(pathRef, nil, bounds);
                addLine = YES;
            }
            layer.path = pathRef;
            CFRelease(pathRef);
            layer.fillColor = [UIColor colorWithWhite:1.f alpha:0.8f].CGColor;//可以调颜色
           
            if (addLine == YES) {
                CALayer *lineLayer = [[CALayer alloc] init];
                CGFloat lineHeight = (1.f / [UIScreen mainScreen].scale);
                lineLayer.frame = CGRectMake(CGRectGetMinX(bounds)+10, bounds.size.height-lineHeight, bounds.size.width-10, lineHeight);
                lineLayer.backgroundColor = tableView.separatorColor.CGColor;
                [layer addSublayer:lineLayer];
            }
            UIView *testView = [[UIView alloc] initWithFrame:bounds];
            [testView.layer insertSublayer:layer atIndex:0];
            testView.backgroundColor = UIColor.clearColor;
            cell.backgroundView = testView;
        }
    }
}
  • 调节tableView上cell上下左右间距,只要创建一个UITableViewCell的子类,重写一下setfrme方法即可以调整。
-(void)setFrame:(CGRect)frame
{
    frame.origin.x -= 30;
    frame.size.width += 55;
   [super setFrame:frame];
}
tableviewcell懒加载位置问题
查了一资料,可能是历史遗留问题,所以tableViewCell在初始化的时候宽高默认是320*44.只有在布局的时候才会调整到设置的高度。所以可以重写layoutSubviews方法。在layoutSubviews里面加载label即可。

QQ分组效果
这里写图片描述

下载地址:http://download.csdn.net/download/u010742414/8650257

  • tableViewCell单选,多选
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
  //单选
//    if ([indexPath isEqual:self.currentIndexPath])
//    {
//        cell.accessoryType = UITableViewCellAccessoryCheckmark;
//
//    }
//    else
//    {
//        cell.accessoryType  = UITableViewCellAccessoryNone;
//    }
    //单选
    if ([indexPath isEqual:self.currentIndexPath])
    {
        cell.accessoryView.hidden = NO;
        UIImageView* accView =[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"icon_address_selected"]];
        accView.frame = CGRectMake(2, 200, 35, 35);
        cell.accessoryView=accView;
    }
    else
    {
        cell.accessoryView.hidden = YES;
    }
//多选
    for (NSIndexPath* index in self.mArraysesected)
    {
          if (![indexPath isEqual:index])
          {
                cell.accessoryType = UITableViewCellAccessoryNone;
          }
       
        if ([indexPath isEqual:index])
        {
            cell.accessoryType = UITableViewCellAccessoryCheckmark;
            return cell;
        }
    }
    return cell;
   
}



}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{
   //单选
//    self.lastIndexPath = self.currentIndexPath;
//    self.currentIndexPath = indexPath;
//    if (self.lastIndexPath)
//    {
//        [tableView reloadRowsAtIndexPaths:@[self.lastIndexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
//    }
//    
//        [tableView reloadRowsAtIndexPaths:@[self.currentIndexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
    //多选
    if ([self.mArraysesected containsObject:indexPath])
    {
        [self.mArraysesected removeObject:indexPath];
    }else{
        [self.mArraysesected addObject:indexPath];
    }
   
    [tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];

}
  • 用tableViewPaln做这样的效果,N个section,一个行,header设置透明色,plan的heade和footer会跟随移动
    这里写图片描述

TbleviewController ios8 删除时添加多个按钮

ios 新的属性
typedef NS_ENUM(NSInteger, UITableViewRowActionStyle) {
    UITableViewRowActionStyleDefault = 0,
    UITableViewRowActionStyleDestructive = UITableViewRowActionStyleDefault,
    UITableViewRowActionStyleNormal
} NS_ENUM_AVAILABLE_IOS(8_0);

NS_CLASS_AVAILABLE_IOS(8_0) @interface UITableViewRowAction : NSObject <NSCopying>

+ (instancetype)rowActionWithStyle:(UITableViewRowActionStyle)style title:(NSString *)title handler:(void (^)(UITableViewRowAction *action, NSIndexPath *indexPath))handler;
/下面实现相关代码
(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return YES;
}

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath

{
    
    return  UITableViewCellEditingStyleDelete;
    
}

-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        
        [self.dataSource removeObjectAtIndex:indexPath.row];
        [self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
    }
}
- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    //设置删除按钮
      UITableViewRowAction *deleteRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"删除"handler:^(UITableViewRowAction *action,NSIndexPath *indexPath) {
          
          [self.dataSource removeObjectAtIndex:indexPath.row];
          [self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
          
      }];
    
    //设置收藏按钮
    UITableViewRowAction *collectRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"收藏"handler:^(UITableViewRowAction *action,NSIndexPath *indexPath) {
        
      
        collectRowAction.backgroundColor = [UIColor greenColor];
 
        UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"收藏" message:@"收藏成功" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alertView show];
        
        
    }];
    //设置置顶按钮
    UITableViewRowAction *topRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"置顶" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {

        
        [self.dataSource exchangeObjectAtIndex:indexPath.row withObjectAtIndex:0];
        
        NSIndexPath *firstIndexPath = [NSIndexPath indexPathForRow:0 inSection:indexPath.section];
        [tableView moveRowAtIndexPath:indexPath toIndexPath:firstIndexPath];
        
    }];
    
    collectRowAction.backgroundEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
    topRowAction.backgroundColor = [UIColor blueColor];
    collectRowAction.backgroundColor = [UIColor grayColor];
    
    return  @[deleteRowAction,collectRowAction,topRowAction];
}

这里写图片描述

TbleviewController 设置滑动范围

TbleviewController 当在一些情境中我们需要我们的tableview 滑动时增大它们的滑动范围时候我们可以调用    self.tableView.contentSize 函数即可
 当tableview 滑动时设置它们的contentSize
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{    
    self.tableView.contentSize = CGSizeMake(0,1000);
}

tableviewController subclassView 不随着一起滚动

添加一个button 等宽与视图的宽度
    tryButton = [UIButtonbuttonWithType:UIButtonTypeCustom];
    tryButton.frame =CGRectMake(0,self.view.frame.size.height-44,self.view.frame.size.width,44);
    // [tryButton setBackgroundImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
    [tryButtonsetBackgroundColor:[UIColor redColor]];
    [tryButtonaddTarget:selfaction:@selector(tryButtonAction)forControlEvents:UIControlEventTouchUpInside];
    [self.tableViewaddSubview:tryButton];

添加在scrollView方法里设置坐标即可

-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    tryButton.frame =CGRectMake(tryButton.frame.origin.x, (self.tableView.frame.size.height-44)+self.tableView.contentOffset.y , tryButton.frame.size.width,tryButton.frame.size.height);
}

去掉最后一条 cell分割线

 if(IOS7){
                cell.separatorInset = UIEdgeInsetsMake(0, 0, 0, cell.bounds.size.width);
            }

获取 tableview 每个cell 的坐标点

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{
  CGRect  popoverRect = [tableView convertRect:[tableView rectForRowAtIndexPath:indexPath] toView:[tableView superview]];

}

给tableview设置缩进级别

-(NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row ==0) {
        return10;
    }
     return 0;
}

TableView重用方法

方法一,子视图少的情况

 for (UIView *view in cell.contentView.subviews) {

    [view removeFromSuperview];
}
或者
  else//当页面拉动的时候 当cell存在并且最后一个存在 把它进行删除就出来一个独特的cell我们在进行数据配置即可避免
    {
        while ([cell.contentView.subviews lastObject] != nil) {
            [(UIView *)[cell.contentView.subviews lastObject] removeFromSuperview];
        }
    }

方法二,缺点,多个不同的cell需要有不同的标识符

}
UIImageView *imageView = [[UIImageView alloc] initWithFra
  }
  UIImageView *imgView = (UIImageView*)[cell.contentView viewWithTag:1000];

方法三,自定义cell,但一般只对固定不变的类进行封装


多个TableView切换的方法

一定要在加载完数据后,reloadData之前确定需要加载的tableViewCell,而且,使用上拉或者加载更多刷新的时候,一样的,否则出现tableCell为nil的情况

ScrollView


  • UIScrollView在手指离开后立即停止滑动
-(void)scrollViewWillBeginDecelerating: (UIScrollView *)scrollView{
    [scrollView setContentOffset:scrollView.contentOffset animated:NO];
}

滑动隐藏tab和nav

-(void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset{

if(velocity.y>0){

//[self.navigationController setNavigationBarHidden:YES animated:YES];

[self setTabBarHidden:YES];

}else{

//[self.navigationController setNavigationBarHidden:NO animated:YES];

[self setTabBarHidden:NO];

}

}


- (void)setTabBarHidden:(BOOL)hidden

{

    UIView *tab = self.tabBarController.view;

    tab.backgroundColor = [UIColor whiteColor];

    CGRect tabRect=self.tabBarController.tabBar.frame;

    if ([tab.subviews count] < 2) {

        return;

    }

    UIView *view;

    if ([[tab.subviews objectAtIndex:0] isKindOfClass:[UITabBar class]]) {

        view = [tab.subviews objectAtIndex:1];

    } else {

        view = [tab.subviews objectAtIndex:0];

    }

    view.backgroundColor = [UIColor clearColor];

    if (hidden) {

        view.frame = tab.bounds;

        tabRect.origin.y=[[UIScreen mainScreen] bounds].size.height+self.tabBarController.tabBar.frame.size.height;

        self.tableView.frame = [UIScreen mainScreen].bounds;
//        self.view.frameHeight+=70;
//        self.tableView.frameHeight+=70;
        [tab bringSubviewToFront:view];

        [view sendSubviewToBack:self.tabBarController.tabBar];

        [UITabBar appearance].translucent = YES;
		//更改superview使用
       // self.viewaa.frameY -=(70+kIPhoneXSub_NavBar_DArea);
        // self.viewaa.frameHeight+=(70+kIPhoneXSub_NavBar_DArea);
    } else {

        view.frame = CGRectMake(tab.bounds.origin.x, tab.bounds.origin.y, tab.bounds.size.width, tab.bounds.size.height);

        tabRect.origin.y=[[UIScreen mainScreen] bounds].size.height-self.tabBarController.tabBar.frame.size.height;

        self.tableView.frame = view.frame;

        [tab bringSubviewToFront:self.tabBarController.tabBar];

        [self.tabBarController.tabBar sendSubviewToBack:view];

        [UITabBar appearance].translucent = NO;

       // self.viewaa.frameY +=(70+kIPhoneXSub_NavBar_DArea);
        // self.viewaa.frameHeight-=(70+kIPhoneXSub_NavBar_DArea);
    }

    [UIView animateWithDuration:0.5f animations:^{

        self.tabBarController.tabBar.frame=tabRect;

    }completion:^(BOOL finished) {

    }];

}

tableView group类型 设置圆角 阴影等

{
    // 圆角弧度半径
    CGFloat cornerRadius = 6.f;
    // 设置cell的背景色为透明,如果不设置这个的话,则原来的背景色不会被覆盖
    cell.backgroundColor = UIColor.clearColor;
    
    // 创建一个shapeLayer
    CAShapeLayer *layer = [[CAShapeLayer alloc] init];
    CAShapeLayer *backgroundLayer = [[CAShapeLayer alloc] init]; //显示选中
    // 创建一个可变的图像Path句柄,该路径用于保存绘图信息
    CGMutablePathRef pathRef = CGPathCreateMutable();
    // 获取cell的size
    // 第一个参数,是整个 cell 的 bounds, 第二个参数是距左右两端的距离,第三个参数是距上下两端的距离
    CGRect bounds = CGRectInset(cell.bounds, DISCELL, 0);
    
    // CGRectGetMinY:返回对象顶点坐标
    // CGRectGetMaxY:返回对象底点坐标
    // CGRectGetMinX:返回对象左边缘坐标
    // CGRectGetMaxX:返回对象右边缘坐标
    // CGRectGetMidX: 返回对象中心点的X坐标
    // CGRectGetMidY: 返回对象中心点的Y坐标
    
    // 这里要判断分组列表中的第一行,每组section的第一行,每组section的中间行
    
    // CGPathAddRoundedRect(pathRef, nil, bounds, cornerRadius, cornerRadius);
    if (indexPath.row == 0) {
        // 初始起点为cell的左下角坐标
        CGPathMoveToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMaxY(bounds));
        // 起始坐标为左下角,设为p,(CGRectGetMinX(bounds), CGRectGetMinY(bounds))为左上角的点,设为p1(x1,y1),(CGRectGetMidX(bounds), CGRectGetMinY(bounds))为顶部中点的点,设为p2(x2,y2)。然后连接p1和p2为一条直线l1,连接初始点p到p1成一条直线l,则在两条直线相交处绘制弧度为r的圆角。
        CGPathAddArcToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMinY(bounds), CGRectGetMidX(bounds), CGRectGetMinY(bounds), cornerRadius);
        CGPathAddArcToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMinY(bounds), CGRectGetMaxX(bounds), CGRectGetMidY(bounds), cornerRadius);
        // 终点坐标为右下角坐标点,把绘图信息都放到路径中去,根据这些路径就构成了一块区域了
        CGPathAddLineToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMaxY(bounds));
        
    } else if (indexPath.row == [tableView numberOfRowsInSection:indexPath.section]-1) {
        // 初始起点为cell的左上角坐标
        CGPathMoveToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMinY(bounds));
        CGPathAddArcToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMaxY(bounds), CGRectGetMidX(bounds), CGRectGetMaxY(bounds), cornerRadius);
        CGPathAddArcToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMaxY(bounds), CGRectGetMaxX(bounds), CGRectGetMidY(bounds), cornerRadius);
        // 添加一条直线,终点坐标为右下角坐标点并放到路径中去
        CGPathAddLineToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMinY(bounds));
    } else {
        // 添加cell的rectangle信息到path中(不包括圆角)
        CGPathAddRect(pathRef, nil, bounds);
    }
    // 把已经绘制好的可变图像路径赋值给图层,然后图层根据这图像path进行图像渲染render
    layer.path = pathRef;
    backgroundLayer.path = pathRef;
    // 注意:但凡通过Quartz2D中带有creat/copy/retain方法创建出来的值都必须要释放
    CFRelease(pathRef);
    // 按照shape layer的path填充颜色,类似于渲染render
//     layer.fillColor = [UIColor colorWithWhite:1.f alpha:0.8f].CGColor;
    layer.fillColor = [UIColor whiteColor].CGColor;
    
//    group设置边框颜色
    layer.lineWidth = 1.5;
    layer.strokeColor = hexColor(0xD7D7D7, 1).CGColor;
    
//    group设置阴影
    RechargeInfo* info=  _ary[indexPath.row];
    if (info.isBottom) {
        layer.shadowOffset = CGSizeMake(0, 4);
        layer.shadowColor = [hexColor(0xcfcfcf, 1) CGColor];
        layer.shadowRadius = .6;
        layer.shadowOpacity = .75f;
    }

    // view大小与cell一致
    UIView *roundView = [[UIView alloc] initWithFrame:bounds];
    // 添加自定义圆角后的图层到roundView中
    [roundView.layer insertSublayer:layer atIndex:0];
    roundView.backgroundColor = UIColor.clearColor;
    
//    roundView.layer.borderWidth = .1f;
//    roundView.layer.backgroundColor = [UIColor grayColor].CGColor;

    // cell的背景view
    cell.backgroundView = roundView;
    
    // 以上方法存在缺陷当点击cell时还是出现cell方形效果,因此还需要添加以下方法
    // 如果你 cell 已经取消选中状态的话,那以下方法是不需要的.
    UIView *selectedBackgroundView = [[UIView alloc] initWithFrame:bounds];
    backgroundLayer.fillColor = [UIColor cyanColor].CGColor;
    [selectedBackgroundView.layer insertSublayer:backgroundLayer atIndex:0];
    selectedBackgroundView.backgroundColor = UIColor.clearColor;
    cell.selectedBackgroundView = selectedBackgroundView;
    
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值