iOS - 版面实现记录五
2015-06-05 21:42
585 查看
思路是使用 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 简单使用
相关文章推荐
- iOS 工作备注
- IOS 开源项目
- IOS 如何选择delegate、notification、KVO?
- iOS战记 ----OC基础语法之战(三)
- iOS战记 ----OC基础语法之战(二)
- 如何将Nios II硬件和软件合成一个文件(NIOS II)烧进EPCS falsh
- IOS开发类书--目录总结
- iOS:KVO/KVC 的概述与使用
- iOS开发者遇到审核失败的原因及解决办法
- 编译vlc for ios
- 制作iOS Ad-Hoc测试应用
- iOS报错 -pie can only be used when targeting iOS 4.2 or later
- iOS开发系列--并行开发其实很容易 --多线程开发
- Mac下顯示當前文件目錄(配置open cv on ios)
- iOS应用程序生命周期(前后台切换,应用的各种状态)详解
- iOS中图片拉伸技巧
- iOS 工程解耦后 消息传递方式
- IOS 获取文本的高度和宽度
- E430(c) 修改版BIOS刷入攻略
- (转载)ios关闭虚拟键盘的几种方法