在UITableView里判断第一行和最后一行
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *identifier = @"NewsTableViewCell";
PersonTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if (!cell) {
cell = [[PersonTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
}
PersonModel *model = _tvData[indexPath.row];
BOOL first = NO;
BOOL last = NO;
if (indexPath.row ==0) {
first = YES;
}
if(indexPath.row == _tvData.count -1){
last = YES;
}
[cell setItem:model isFirst:first isLast:last];
return cell;
}
在自定义Cell里画圆角
-(void)setItem:(PersonModel *)model isFirst:(BOOL)isFirst isLast:(BOOL)isLast{
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:_bgView.layer.bounds byRoundingCorners:UIRectCornerAllCorners cornerRadii:CGSizeMake(0, 0)];
if (isFirst && isLast) {
maskPath = [UIBezierPath bezierPathWithRoundedRect:_bgView.layer.bounds byRoundingCorners:UIRectCornerAllCorners cornerRadii:CGSizeMake(SCREEN_3SPACE(10), SCREEN_3SPACE(10))];
}else{
if (isFirst) {
maskPath = [UIBezierPath bezierPathWithRoundedRect:_bgView.layer.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(SCREEN_3SPACE(10), SCREEN_3SPACE(10))];
}
if (isLast) {
maskPath = [UIBezierPath bezierPathWithRoundedRect:_bgView.layer.bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(SCREEN_3SPACE(10), SCREEN_3SPACE(10))];
}
}
CAShapeLayer *maskLayer = [CAShapeLayer new];
maskLayer.frame = _bgView.layer.bounds;
maskLayer.path = maskPath.CGPath;
_bgView.layer.mask = maskLayer;
_nameLabel.text = model.name;
_phoneLabel.text = model.phone;
_timeLabel.text = [NSString stringWithFormat:@"注册时间:%@",model.date];
}