iOS每日一记之———————————————为Cell设置部分圆角 类似于ipad的设置界面效果
来源:互联网 发布:在淘宝上如何做代理 编辑:程序博客网 时间:2024/05/22 03:27
需求图是这样的
整个是个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设置部分圆角 类似于ipad的设置界面效果
- iOS每日一记之———————————————模仿今日头条栏目选择效果 并且附加cell颤抖效果
- iOS 每日一记 之—— application的生命周期
- tableview——设置cell的文字居中和透明度
- ios开发——解决UICollectionView的cell间距与设置不符问题
- ios开发——解决UICollectionView的cell间距与设置不符问题
- iOS开发实战——CollectionView中cell的间距设置
- iOS——关于Cell上Button点击效果
- ios——图片、界面切换效果
- iOS —— Cell + UIMenuController
- iOS每日一记——————之简单的去重操作。。。。
- iOS开发UI篇—以微博界面为例使用纯代码自定义cell程序编码全过程(一)
- iOS学习之——View的圆角设置
- android开发之——设置TextView文本为跑马灯效果
- iOS开发UI篇—以微博界面为例使用纯代码自定义cell程序编码全过程
- iOS开发UI篇—以微博界面为例使用纯代码自定义cell程序编码全过程
- IOS学习之——自定义的Cell
- IOS学习之——自定义的Cell (代码)
- docker-compose是干什么的?
- WEB阶段中文乱码解决方式总结:
- Android中Spinner控件的使用
- Java NIO初步了解
- ITK 形态学处理(Morph process)
- iOS每日一记之———————————————为Cell设置部分圆角 类似于ipad的设置界面效果
- 安装sql sever management studio出现29506错误
- STM32 IIC的学习
- WPF中动态创建TreeView。
- 设计模式一 模版模式
- Netty 实现 WebSocket 聊天功能
- arduino UNO、arduino 2560和can总线-基于mcp2515的一些基础通讯
- Laravel中缓存的使用
- 【GDOI2017模拟二试4.12】树上路径