iOS开发资料收集区iOSios实用开发技巧

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

2016-07-21  本文已影响2512人  Senior丶
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;
}

上一篇 下一篇

猜你喜欢

热点阅读