可自动适应高度的不同类型圆角的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;
}
}