How is a rounded rect view with transparency done on iphone?

前端 未结 5 1741
你的背包
你的背包 2020-11-30 17:38

A lot of apps pop up a transparent view with rounded corners and an activityIndicator when running a time consuming operation.

How is this rounding done and is it po

5条回答
  •  误落风尘
    2020-11-30 18:39

    I abstracted out @lostInTransit's response into this function:

    static void ContextAddRoundedRect(CGContextRef c, CGRect rect, CGFloat radius) {
      CGFloat minX = CGRectGetMinX(rect);
      CGFloat maxX = CGRectGetMaxX(rect);
      CGFloat minY = CGRectGetMinY(rect);
      CGFloat maxY = CGRectGetMaxY(rect);
    
      CGContextMoveToPoint(c, minX + radius, minY);
      CGContextAddArcToPoint(c, maxX, minY, maxX, minY + radius, radius);
      CGContextAddArcToPoint(c, maxX, maxY, maxX - radius, maxY, radius);
      CGContextAddArcToPoint(c, minX, maxY, minX, maxY - radius, radius);
      CGContextAddArcToPoint(c, minX, minY, minX + radius, minY, radius);
    }
    

    which places the path onto the context for you to do with as you may

    slightly different CoreGraphics calls and i didn't close the path, in case you want to add that

    CGContextFillPath(c);
    

提交回复
热议问题