#import <UIKit/UIKit.h> NS_ASSUME_NONNULL_BEGIN @interface UIView (PersonCategory) - (void)shmaas_addRoundedCorners:(UIRectCorner)corners frame:(CGRect)frame cornerRadius:(CGFloat)cornerRadius; @end NS_ASSUME_NONNULL_END
#import "UIView+PersonCategory.h" @implementation UIView (PersonCategory) /// 部分圆角 - (void)shmaas_addRoundedCorners:(UIRectCorner)corners frame:(CGRect)frame cornerRadius:(CGFloat)cornerRadius { UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:frame byRoundingCorners:corners cornerRadii:CGSizeMake(cornerRadius, cornerRadius)]; CAShapeLayer *maskLayer = [CAShapeLayer layer]; maskLayer.frame = frame; maskLayer.path = maskPath.CGPath; self.layer.mask = maskLayer; } @end
/// 设置cell圆角 - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{ if (self.inputSearchText.length > 0) { if (indexPath.section == 0){ if (self.viewModel.poi2SitesResModel == nil || self.viewModel.poi2SitesResModel.pois.count == 0) { // 无poi匹配结果 [cell shmaas_addRoundedCorners:UIRectCornerAllCorners frame:cell.bounds cornerRadius:10]; } else { // 搜索结果 if (indexPath.row == 0) { [cell shmaas_addRoundedCorners:UIRectCornerTopLeft | UIRectCornerTopRight frame:cell.bounds cornerRadius:10]; } else if (indexPath.row == self.viewModel.poi2SitesResModel.pois.count-1) { [cell shmaas_addRoundedCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight frame:cell.bounds cornerRadius:10]; } } } else if (indexPath.section == 1) { if (indexPath.row == 0) { [cell shmaas_addRoundedCorners:UIRectCornerTopLeft | UIRectCornerTopRight frame:cell.bounds cornerRadius:10]; } else{ if (_stationData.recommands.count > 0) { if (indexPath.row == _stationData.recommands.count) { [cell shmaas_addRoundedCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight frame:cell.bounds cornerRadius:10]; } } else { if (indexPath.row == _stationData.sites.count) { [cell shmaas_addRoundedCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight frame:cell.bounds cornerRadius:10]; } } } } } else { if (indexPath.section == 0){ if (indexPath.row == 0) { [cell shmaas_addRoundedCorners:UIRectCornerTopLeft | UIRectCornerTopRight frame:cell.bounds cornerRadius:10]; } else if (indexPath.row == _stationData.histories.count-1) { [cell shmaas_addRoundedCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight frame:cell.bounds cornerRadius:10]; } } else if (indexPath.section == 1) { if (indexPath.row == 0) { [cell shmaas_addRoundedCorners:UIRectCornerTopLeft | UIRectCornerTopRight frame:cell.bounds cornerRadius:10]; } else { if (_stationData.recommands.count > 0) { if (indexPath.row == _stationData.recommands.count) { [cell shmaas_addRoundedCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight frame:cell.bounds cornerRadius:10]; } } else { if (indexPath.row == _stationData.sites.count) { [cell shmaas_addRoundedCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight frame:cell.bounds cornerRadius:10]; } } } } } }
标签:indexPath,圆角,shmaas,frame,OC,addRoundedCorners,cell,cornerRadius From: https://www.cnblogs.com/qingzZ/p/17722415.html