美文网首页
2018-07-22

2018-07-22

作者: 候鹿人 | 来源:发表于2018-07-22 17:04 被阅读1次

//

//  InsuranceEvaluationRutleView.m

//  tesr

//

//  Created by邓志强 on 2018/7/22.

//  Copyright © 2018年 邓志强. All rights reserved.

//

#import "InsuranceEvaluationRutleView.h"

@implementation InsuranceEvaluationRutleView

- (instancetype)initWithFrame:(CGRect)frame

                 DefalutColor:(UIColor *)color

               andSelectColor:(UIColor *)selectColor

                  andAllCount:(int)allCount

               andSelectCount:(int)selectCount{

    self = [super initWithFrame:frame];

    if (self) {

        CGFloat w = frame.size.width/allCount - 1;

        CGFloat h = frame.size.height;

        for (int i = 1; i <= allCount; i++) {

            UILabel *view = [[UILabel alloc]initWithFrame:CGRectMake(w*(i-1), 0, w, h)];

            view.backgroundColor = i <= selectCount ? selectColor:color;

            CAShapeLayer *maskLayer = [CAShapeLayer layer];

            if (allCount == 1) {

                maskLayer.path = [UIBezierPath bezierPathWithRoundedRect:view.bounds byRoundingCorners: UIRectCornerAllCorners cornerRadii: (CGSize){0.5*h, 0.5*h}].CGPath;

                view.layer.masksToBounds =YES;

                view.layer.mask = maskLayer;

            }else if (i == 1) {

                maskLayer.path = [UIBezierPath bezierPathWithRoundedRect:view.bounds byRoundingCorners: UIRectCornerBottomLeft | UIRectCornerTopLeft cornerRadii: (CGSize){0.5*h, 0.5*h}].CGPath;

                view.layer.masksToBounds =YES;

                view.layer.mask = maskLayer;

            }else if (i == allCount) {

                maskLayer.path = [UIBezierPath bezierPathWithRoundedRect:view.bounds byRoundingCorners: UIRectCornerBottomRight | UIRectCornerTopRight cornerRadii: (CGSize){0.5*h, 0.5*h}].CGPath;

                view.layer.masksToBounds =YES;

                view.layer.mask = maskLayer;

            } 

            [self addSubview:view];

            if(i

                UILabel *line = [[UILabel alloc]initWithFrame:CGRectMake(w*i-1, 0, 1, h)];

                line.backgroundColor = [UIColor whiteColor];

                [self addSubview:line];

            }

        }

    }

    return self;

}

@end

相关文章

网友评论

      本文标题:2018-07-22

      本文链接:https://www.haomeiwen.com/subject/yntrmftx.html