iOS每日一记之———————————————为Cell设置部分圆角 类似于ipad的设置界面效果
2017-04-18 15:02
477 查看
需求图是这样的
![](https://img-blog.csdn.net/20170418145653065?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcXFfMjYzNTk3NjM=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
整个是个tableView 而且要求第一个cell和最后一个cell是部分圆角 有人会说这很简单啊 你设置第一个cell和最后一个cell的contentView部分圆角不就好了么 然而这样实现不了的、。。。。。 我在cell上面放了个白色的View 然后控制白色View的不同圆角情况依旧失败。。。。。想了半天实在不行加个图片好了 但是因为功能比较大 不能再添加无效图片了 所以只好作罢 。。。。 之后在stackOverFollow上面找到了答案 具体实现如下 用到了disPlayCell方法
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
NSInteger sectionCount = [tableView numberOfRowsInSection:indexPath.section] - 1;// section row 个数
CGRect bounds = CGRectInset(cell.bounds, 12, 0); // 显示的cell 点击区域
// 2.再盖一个 mask
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];// 用于蒙板
// section 只有一个时。
if (indexPath.row == 0 && indexPath.row == sectionCount) {
[maskLayer setPath:[UIBezierPath bezierPathWithRoundedRect:bounds cornerRadius:radius].CGPath];
// 第一个 row
} else if (indexPath.row == 0) {
[maskLayer setPath:[UIBezierPath bezierPathWithRoundedRect:bounds
byRoundingCorners:(UIRectCornerTopLeft|UIRectCornerTopRight)
cornerRadii:CGSizeMake(radius, radius)].CGPath];
// 最后一个 row
} else if (indexPath.row == sectionCount) {
[maskLayer setPath:[UIBezierPath bezierPathWithRoundedRect:bounds
byRoundingCorners:(UIRectCornerBottomLeft|UIRectCornerBottomRight)
cornerRadii:CGSizeMake(radius, radius)].CGPath];
// 中间 row
} else {
UIBezierPath *path = [UIBezierPath bezierPathWithRect:bounds];
[maskLayer setPath:path.CGPath];
}
// 2.mask
[cell setMaskView:[[UIView alloc] initWithFrame:cell.bounds]];
[cell.maskView.layer insertSublayer:maskLayer atIndex:0];
[cell.maskView.layer setMasksToBounds:YES];
[cell setClipsToBounds:YES];
}
OK这样就行了 disPlaycell cell将要展示的时候会调用
整个是个tableView 而且要求第一个cell和最后一个cell是部分圆角 有人会说这很简单啊 你设置第一个cell和最后一个cell的contentView部分圆角不就好了么 然而这样实现不了的、。。。。。 我在cell上面放了个白色的View 然后控制白色View的不同圆角情况依旧失败。。。。。想了半天实在不行加个图片好了 但是因为功能比较大 不能再添加无效图片了 所以只好作罢 。。。。 之后在stackOverFollow上面找到了答案 具体实现如下 用到了disPlayCell方法
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
NSInteger sectionCount = [tableView numberOfRowsInSection:indexPath.section] - 1;// section row 个数
CGRect bounds = CGRectInset(cell.bounds, 12, 0); // 显示的cell 点击区域
// 2.再盖一个 mask
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];// 用于蒙板
// section 只有一个时。
if (indexPath.row == 0 && indexPath.row == sectionCount) {
[maskLayer setPath:[UIBezierPath bezierPathWithRoundedRect:bounds cornerRadius:radius].CGPath];
// 第一个 row
} else if (indexPath.row == 0) {
[maskLayer setPath:[UIBezierPath bezierPathWithRoundedRect:bounds
byRoundingCorners:(UIRectCornerTopLeft|UIRectCornerTopRight)
cornerRadii:CGSizeMake(radius, radius)].CGPath];
// 最后一个 row
} else if (indexPath.row == sectionCount) {
[maskLayer setPath:[UIBezierPath bezierPathWithRoundedRect:bounds
byRoundingCorners:(UIRectCornerBottomLeft|UIRectCornerBottomRight)
cornerRadii:CGSizeMake(radius, radius)].CGPath];
// 中间 row
} else {
UIBezierPath *path = [UIBezierPath bezierPathWithRect:bounds];
[maskLayer setPath:path.CGPath];
}
// 2.mask
[cell setMaskView:[[UIView alloc] initWithFrame:cell.bounds]];
[cell.maskView.layer insertSublayer:maskLayer atIndex:0];
[cell.maskView.layer setMasksToBounds:YES];
[cell setClipsToBounds:YES];
}
OK这样就行了 disPlaycell cell将要展示的时候会调用
相关文章推荐
- iOS软件开发 设置cell动画效果
- iOS 设置视图的圆角效果
- iOS设置圆角矩形和阴影效果
- iOS设置圆角和投影效果 解决设置了圆角投影效果设置不上问题
- iOS开发笔记之设置view部分圆角
- iOS 设置头像圆角效果
- iOS每日一记之———————————————模仿今日头条栏目选择效果 并且附加cell颤抖效果
- iOS 设置tableView每个分区cell圆角
- iOS开发(iPad/iPhone)设置app界面 默认横向显示的两种方法
- iOS高效的设置圆角效果
- iOS每日一记之———————————————图片圆角的处理
- iOS UI篇- cell.imageView 设置圆角
- iOS-设置阴影和圆角效果
- iOS UITableViewCell cell.imageView 设置圆角
- IOS学习 网络HTTP Get和Post请求与登录界面加密 涉及按钮边框圆角与颜色设置
- iOS小技巧-UITableView取消或设置cell的选中效果
- iOS每日一记之 设置UIImage的圆角
- iOS设置圆角矩形和阴影效果
- iOS开发(iPad/iPhone)设置app界面 默认横向显示的两种方法
- iOS view圆角设置同时又不影响子视图超出父视图部分显示