recherche

Maison  >  Questions et réponses  >  le corps du texte

ios - 在image上切一个透明的圆

结构层次:UIView->UIImageView->UIImage,即把带有图片的imageview添加到UIView上,现在要在图片上 切一个透明的圆

PHPzPHPz2893 Il y a quelques jours271

répondre à tous(3)je répondrai

  • 迷茫

    迷茫2017-04-18 09:05:31

    Référez-vous au code suivant :

    - (void)addShadowView {
        self.hollowFrames = @[[NSValue valueWithCGPoint:CGPointMake(20.0, 20.0)], [NSValue valueWithCGPoint:CGPointMake(120.0, 20.0)]];
    
        int radius = 15.0;
        UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height) cornerRadius:0];
    
        for (NSValue *point in self.hollowFrames) {
            UIBezierPath *circlePath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(point.CGPointValue.x, point.CGPointValue.y, 2.0*radius, 2.0*radius) cornerRadius:radius];
            [path appendPath:circlePath];
        }
    
        [path setUsesEvenOddFillRule:YES];
    
        CAShapeLayer *fillLayer = [CAShapeLayer layer];
        fillLayer.path = path.CGPath;
        fillLayer.fillRule = kCAFillRuleEvenOdd;
        fillLayer.fillColor = [UIColor blackColor].CGColor;
        fillLayer.opacity = 0.5;
        [self.layer addSublayer:fillLayer];
    }
    

    réfs : http://stackoverflow.com/a/18925731/4733603

    répondre
    0
  • PHP中文网

    PHP中文网2017-04-18 09:05:31

    Utilisez l'outil PS Pen pour le décrire, ou utilisez l'outil de sélection magique pour sélectionner et supprimer la partie blanche.

    répondre
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-18 09:05:31

    S'il s'agit d'une page web : l'attribut border-radius du CSS peut vous inspirer.

    <html>
    <head>
     <style>
       .box{
         width:50px;
         height:50px;
         border-radius:50%;
         overflow:hidden;
       }
     </style>
    </head>
    <body>
     <p class="box">
       <img src="./images/1.jpg" />
     </p>
    </body>
    </html>

    répondre
    0
  • Annulerrépondre