iOS 虚线框设置

2021-08-26  本文已影响0人  ios_暗夜行者

UIButton*btn =[[UIButton alloc]initWithFrame:CGRectMake(20*sizeScale, (50*sizeScale-44*sizeScale)/2, 335*sizeScale, 44*sizeScale)];

        [cell.contentViewaddSubview:btn];

//        [btn mas_makeConstraints:^(MASConstraintMaker *make) {

//            make.centerX.mas_equalTo(cell.contentView.mas_centerX);

//            make.centerY.mas_equalTo(cell.contentView.mas_centerY);

//            make.width.mas_equalTo(335*sizeScale);

//            make.height.mas_equalTo(44*sizeScale);

//        }];

        [btnsetTitle:LocalizedString(@"上传")forState:0];

        [btnsetTitleColor:[UIColorcolorWithHexString:@"#242424"]forState:0];

        btn.titleLabel.font=FONT_14;

        //添加虚线边框

        CAShapeLayer*border = [CAShapeLayer layer];

        //虚线的颜色

        border.strokeColor=[UIColorcolorWithHexString:@"#D5D5D5"].CGColor;

        //填充的颜色

        border.fillColor= [UIColorclearColor].CGColor;

        //设置路径

        //border.path = [UIBezierPath bezierPathWithRoundedRect:btn.bounds cornerRadius:6].CGPath;

        //btn.layer.cornerRadius =6*sizeScale;

        //btn.clipsToBounds =YES;

        border.path= [UIBezierPathbezierPathWithRect:btn.bounds].CGPath;

        border.frame= btn.bounds;

        //虚线的宽度

        border.lineWidth=1.0f;

        //设置线条的样式

        //border.lineCap = @"square";

        //设置虚线的间隔

        border.lineDashPattern=@[@4,@2];

        [btn.layeraddSublayer:border];

上一篇 下一篇

猜你喜欢

热点阅读