iOS cell悬浮效果(适用TableView和CollectionView)

  • 先上效果图

1.png
  • 实现方式

只需要在自定义cell上加上一个view,然后把view设置边框阴影

+ (instancetype)cellWithTableView:(UITableView *)tableView{
    static NSString *ID = @"cell";
    XTTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (!cell) {
        cell = [[XTTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
        CGFloat W = [UIScreen mainScreen].bounds.size.width;
        
        //创建一个UIView比cell.contentView小一圈
        UIView *view  = [[UIView alloc] initWithFrame:CGRectMake(10, 5, W - 20, 90)];
        view.backgroundColor = [UIColor whiteColor];
        //给view边框设置阴影
        view.layer.shadowOffset = CGSizeMake(1,1);
        view.layer.shadowOpacity = 0.3;
        view.layer.shadowColor = [UIColor blackColor].CGColor;
        [cell.contentView addSubview:view];
    }
    return cell;
}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,964评论 25 709
  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 12,267评论 4 61
  • 我是一个专科生,毕业半年了。 刚刚从一个做教育培训的公司辞职,突然对未来有点迷茫。 作为一个专科生,出去是有很多的...
    妖幺灵阅读 1,127评论 0 1
  • OGNL Object-Graph Navigation Language ---- 对象视图导航语言 语法 存入...
    蕊er阅读 1,476评论 0 0
  • 摘要: 主要核心部件: Remoting: 网络通信框架,实现了 sync-over-async 和 reques...
    ITsupuerlady阅读 349评论 0 0