美文网首页
iOS View指定圆某个角

iOS View指定圆某个角

作者: ShanJiJi | 来源:发表于2017-09-07 12:04 被阅读14次

    在开发中会遇到需要一个View只圆某个角,例如指定上方两个的角进行圆角处理,方法如下:

     UILabel * exChangeLabel = [[UILabel alloc]initWithFrame:CGRectMake(5, 10, self.view.width-10 , 20)]; 
     exChangeLabel.backgroundColor = setColor(0, 0, 0, 0.8); 
     exChangeLabel.textAlignment = NSTextAlignmentCenter; 
     exChangeLabel.textColor = [UIColor whiteColor]; 
     // exChangeLabel.layer.masksToBounds = YES;
     // exChangeLabel.layer.cornerRadius = 10; 
     UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:exChangeLabel.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(7, 7)];
     CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
     maskLayer.frame = exChangeLabel.bounds;
     maskLayer.path = maskPath.CGPath;
     exChangeLabel.layer.mask = maskLayer;
    
    

    相关文章

      网友评论

          本文标题:iOS View指定圆某个角

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