美文网首页
iOS 圆角设置

iOS 圆角设置

作者: 候鸟0706 | 来源:发表于2018-12-05 14:29 被阅读0次

    使用CAShapeLayer和UIBezierPath设置圆角

     UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, ScreenHeight - 50, ScreenWidth, 50)];
        [self.view addSubview:bottomView];
       
        UIBezierPath *maskPath = [UIBezierPath  bezierPathWithRoundedRect:bottomView.bounds byRoundingCorners:UIRectCornerTopRight|UIRectCornerTopLeft cornerRadii:bottomView.bounds.size];
        CAShapeLayer *maskLayer = [[CAShapeLayer alloc]init];
        //设置大小
        maskLayer.frame = bottomView.bounds;
        //设置图形样子
        maskLayer.path = maskPath.CGPath;
        bottomView.layer.mask = maskLayer;
        bottomView.clipsToBounds = YES;
       
        UIButton *scoreButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 90, 50)];
        [bottomView addSubview:scoreButton];
        scoreButton.backgroundColor = RGB(75, 185, 120);
        [scoreButton setTitle:@"200 积分" forState:UIControlStateNormal];
        scoreButton.titleLabel.font = [UIFont systemFontOfSize:14];
       
        UIButton *jiedaButton = [[UIButton alloc] initWithFrame:CGRectMake(90, 0, ScreenWidth - 90, 50)];
        [bottomView addSubview:jiedaButton];
        jiedaButton.backgroundColor = RGB(235, 175, 88);
        [jiedaButton setTitle:@"解答" forState:UIControlStateNormal];
        [jiedaButton addTarget:self action:@selector(answerDidClicked) forControlEvents:UIControlEventTouchUpInside];
        jiedaButton.titleLabel.font = [UIFont systemFontOfSize:14];

    指定需要成为圆角的的角

    + (UIBezierPath *)bezierPathWithRoundedRect:(CGRect)rect

                              byRoundingCorners:(UIRectCorner)corners

                                    cornerRadii:(CGSize)cornerRadii

    corners参数指定了要成为圆角的角, 枚举类型如下:

    typedef NS_OPTIONS(NSUInteger, UIRectCorner) {

        UIRectCornerTopLeft    =1<<0,

        UIRectCornerTopRight    =1<<1,

        UIRectCornerBottomLeft  =1<<2,

        UIRectCornerBottomRight =1<<3,

        UIRectCornerAllCorners  = ~0UL};

    相关文章

      网友评论

          本文标题:iOS 圆角设置

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