iOS - 版面实现记录五

版面记录五

思路是使用 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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值