美文网首页iOS开发资料收集区iOSios实用开发技巧
iOS cell悬浮效果(适用TableView和Collect

iOS cell悬浮效果(适用TableView和Collect

作者: Senior丶 | 来源:发表于2016-07-21 13:43 被阅读2512次
  • 先上效果图

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;
}

相关文章

网友评论

    本文标题:iOS cell悬浮效果(适用TableView和Collect

    本文链接:https://www.haomeiwen.com/subject/qnebjttx.html