设置cell不同类型的圆角

可自动适应高度的不同类型圆角的cell
思路:设置三个背景view,topView、midView、botView。其中topView和botViewm是顶部和底部圆角,midView的top是topView的底(bottom),bottom是botView的顶(top)。只需要顶部的圆角,就把botView高度更新为0,同理只需要底部圆角就把topView高度更新为0。同时需要两个圆角,就更新topView和botView高度为10。

#import "LTextViewRTextView_AutoCell.h"

@interface LTextViewRTextView_AutoCell ()<UITextViewDelegate>

@end

@implementation LTextViewRTextView_AutoCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setCornerView];
    }
    return self;
}
-(void)setCornerView{
    
    UIImageView *imageViewTop = [[UIImageView alloc] init];
    [self.contentView addSubview:imageViewTop];
    [imageViewTop mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.height.mas_equalTo(WMAKENEW(10));
        make.top.mas_equalTo(WMAKENEW(0));
    }];
    
    UIImageView *imageViewBot = [[UIImageView alloc] init];
    [self.contentView addSubview:imageViewBot];
    [imageViewBot mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.bottom.mas_equalTo(WMAKENEW(0));
        make.height.mas_equalTo(WMAKENEW(10));
    }];
    
    
    UIBezierPath *maskPath;
    CGRect cellSize = CGRectMake(0, 0, SCREEN_WIDTH-2*TableView_Left, WMAKENEW(10));
    maskPath = [UIBezierPath bezierPathWithRoundedRect:cellSize byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(WMAKENEW(7), WMAKENEW(7))];
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.frame = cellSize;
    maskLayer.path = maskPath.CGPath;
    imageViewTop.layer.mask = maskLayer;
    imageViewTop.clipsToBounds = YES;
    
    UIBezierPath *maskPath1;
    maskPath1 = [UIBezierPath bezierPathWithRoundedRect:cellSize byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(WMAKENEW(7), WMAKENEW(7))];
    CAShapeLayer *maskLayer1 = [[CAShapeLayer alloc] init];
    maskLayer1.frame = cellSize;
    maskLayer1.path = maskPath1.CGPath;
    imageViewBot.layer.mask = maskLayer1;
    imageViewBot.clipsToBounds = YES;
    
    UIView *backkkk = [[UIView alloc] init];
    [self.contentView addSubview:backkkk];
    [backkkk mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        **make.bottom.equalTo(imageViewBot.mas_top);
        make.top.equalTo(imageViewTop.mas_bottom);**
    }];
    
    imageViewTop.backgroundColor= backkkk.backgroundColor  = imageViewBot.backgroundColor = [Support_Color Color_Facility_CellBackGround];
    self.topCornerView = imageViewTop;
    self.bottomCornerView = imageViewBot;
}
#pragma mark---显示圆角 /** 设置圆角 0顶部圆角,1底部圆角,2没有圆角,3同时圆角*/
-(void)showCorner:(NSInteger)whichStyle{
    CGFloat maxHeight = WMAKENEW(10);
    CGFloat minHeight = 0;
    switch (whichStyle) {
        case 0:
            [self.topCornerView mas_updateConstraints:^(MASConstraintMaker *make) {
                make.height.mas_equalTo(maxHeight);
            }];
            [self.bottomCornerView mas_updateConstraints:^(MASConstraintMaker *make) {
                make.height.mas_equalTo(minHeight);
            }];
            
            break;
        case 1:
            [self.bottomCornerView mas_updateConstraints:^(MASConstraintMaker *make) {
                make.height.mas_equalTo(maxHeight);
            }];
            [self.topCornerView mas_updateConstraints:^(MASConstraintMaker *make) {
                make.height.mas_equalTo(minHeight);
            }];
            
            break;
        case 2:
            [self.topCornerView mas_updateConstraints:^(MASConstraintMaker *make) {
                make.height.mas_equalTo(minHeight);
            }];
            [self.bottomCornerView mas_updateConstraints:^(MASConstraintMaker *make) {
                make.height.mas_equalTo(minHeight);
            }];
            
            break;
        case 3:
            [self.topCornerView mas_updateConstraints:^(MASConstraintMaker *make) {
                make.height.mas_equalTo(maxHeight);
            }];
            [self.bottomCornerView mas_updateConstraints:^(MASConstraintMaker *make) {
                make.height.mas_equalTo(maxHeight);
            }];
            
            break;
        default:
            break;
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值