iOS - 版面实现记录五
来源:互联网 发布:软件测试人员招聘 编辑:程序博客网 时间:2024/04/29 08:15
思路是使用 UICollectionViewFlowLayout 的 UICollectionView,注册两个 Cell,一左一右。其中灰色线绘制代码加到 Cell 的 init 方法中,如下:
UIBezierPath * leftPath = [[UIBezierPath alloc]init]; //create path [leftPath moveToPoint:CGPointMake(frame.size.width, 0)]; [leftPath addLineToPoint:CGPointMake(frame.size.width, frame.size.height)]; [leftPath moveToPoint:CGPointMake(frame.size.width, frame.size.height*0.6)]; [leftPath addLineToPoint:CGPointMake(frame.size.width*0.5, frame.size.height*0.6)]; //create shape layer CAShapeLayer * lineLayer = [CAShapeLayer layer]; lineLayer.strokeColor = [UIColor grayColor].CGColor; lineLayer.lineWidth = 3; lineLayer.path = leftPath.CGPath; [self.layer addSublayer:lineLayer];
右边同理。
Cell 的代码:
@interface ViewHomeMenuCollectionCellSmall : ViewHomeMenuCollectionSuper {}@property (nonatomic, strong) UILabel * titleLabel;@property (nonatomic, strong) EGOImageView * imageView;@end@implementation ViewHomeMenuCollectionCellSmall- (instancetype)initWithFrame:(CGRect)frame{ self = [super initWithFrame:frame]; if (self) { self.backgroundColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:1]; self.layer.cornerRadius = CELLLAYERCORNER; self.layer.masksToBounds = YES; UIBezierPath * leftPath = [[UIBezierPath alloc]init]; //create path [leftPath moveToPoint:CGPointMake(frame.size.width, 0)]; [leftPath addLineToPoint:CGPointMake(frame.size.width, frame.size.height)]; [leftPath moveToPoint:CGPointMake(frame.size.width, frame.size.height*0.6)]; [leftPath addLineToPoint:CGPointMake(frame.size.width*0.5, frame.size.height*0.6)]; //create shape layer CAShapeLayer * lineLayer = [CAShapeLayer layer]; lineLayer.strokeColor = [UIColor grayColor].CGColor; lineLayer.lineWidth = 3; lineLayer.path = leftPath.CGPath; [self.layer addSublayer:lineLayer]; self.imageView = [[EGOImageView alloc]init]; [self.imageView setFrame:CGRectMake(0, 0, CELLIMAGESCALEWIDTH, CELLIMAGESCALEHIGHT)]; [self.imageView setCenter:CGPointMake(CELLIMAGECENTERX, frame.size.height*0.6)]; self.imageView.layer.borderColor = [[UIColor lightGrayColor]CGColor]; self.imageView.layer.borderWidth = 2; self.imageView.layer.cornerRadius = self.imageView.frame.size.width/2; self.imageView.layer.masksToBounds = YES; [self.imageView setBackgroundColor:[UIColor yellowColor]]; [self addSubview:self.imageView]; self.titleLabel = [[UILabel alloc]init]; [self.titleLabel setFrame:CGRectMake(0, self.imageView.frame.origin.y + self.imageView.frame.size.height + 2, frame.size.width, 15)]; self.titleLabel.backgroundColor = [UIColor clearColor]; self.titleLabel.textColor = [UIColor blackColor]; [self.titleLabel setTextAlignment:NSTextAlignmentCenter]; self.titleLabel.numberOfLines = 0; self.titleLabel.font = [UIFont systemFontOfSize:15]; [self addSubview:self.titleLabel]; } return self;}@end
参考:
CAShapeLayer
UIBezierPath 简单使用
0 0
- iOS - 版面实现记录五
- iOS - 版面实现记录一
- iOS - 版面实现记录二
- iOS - 版面实现记录三
- iOS - 版面实现记录四
- IOS基础知识记录五(简单手电筒)
- 设计中的版面艺术!你造吗?(五)
- iOS工作记录五:View,UIViewController的执行顺序,生命周期
- 在iOS上实现Cover Flow (五)
- iOS消息推送实现过程记录
- iOS消息推送实现过程记录
- 转:iOS消息推送实现过程记录
- iOS消息推送实现过程记录
- 2015.8.7记录iOS侧滑实现
- 记录集分页显示策略五种实现方法
- 记录集分页显示策略五种实现方法
- Spring Security调研记录【五】--基于Cas实现单点登录
- 算法学习记录五(C++)--->两个栈实现队列
- Android系统手机端抓包方法(tcpdump)
- Git远程操作详解
- php+MySQL图书管理系统(一)
- An Adaptive Communication Architecture for Wireless Sensor Networks
- Java异常的处理
- iOS - 版面实现记录五
- 归一化
- quick接入SDK
- icpc2015 D Cutting Cheese(二分+球缺体积)
- 33333
- IDF实验室-特殊的日子
- 面试题22栈的压入、弹出序列
- QQ通信原理及QQ是怎么穿透内网进行通信的?
- 海量数据处理技术(1): 散列技术