2018-07-22

//

//  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

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容