redribben

rendering

Jun 4th, 2015
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. + (UIBezierPath *) trianglePathWithSize: (CGSize) size;
  2. {
  3.     CGContextRef context = UIGraphicsGetCurrentContext();
  4.     CGContextSaveGState(context);
  5.     CGContextSetAlpha(context, 0.9);
  6.     CGContextBeginTransparencyLayer(context, NULL);
  7.    
  8.    
  9.     UIBezierPath *circleOutlinePath = [UIBezierPath bezierPath];
  10.     circleOutlinePath.lineJoinStyle = kCGLineJoinMiter;
  11.    
  12.     [circleOutlinePath moveToPoint: CGPointMake(165.83, 165.69)];
  13.     [circleOutlinePath addCurveToPoint: CGPointMake(165.83, 33.81) controlPoint1: CGPointMake(202.06, 129.27) controlPoint2: CGPointMake(202.06, 70.23)];
  14.     [circleOutlinePath addCurveToPoint: CGPointMake(34.67, 33.81) controlPoint1: CGPointMake(129.61, -2.6) controlPoint2: CGPointMake(70.89, -2.6)];
  15.     [circleOutlinePath addCurveToPoint: CGPointMake(34.67, 165.69) controlPoint1: CGPointMake(-1.56, 70.23) controlPoint2: CGPointMake(-1.56, 129.27)];
  16.     [circleOutlinePath addCurveToPoint: CGPointMake(165.83, 165.69) controlPoint1: CGPointMake(70.89, 202.1) controlPoint2: CGPointMake(129.61, 202.1)];
  17.     [circleOutlinePath closePath];
  18.    
  19.     CGContextEndTransparencyLayer(context);
  20.     CGContextRestoreGState(context);
  21.    
  22.     return circleOutlinePath;
  23. }
  24.  
  25.  
  26.  
  27. - (UIImage *) imageWithStrokeColor: (UIColor *) strokeColor fillColor: (UIColor *)
  28.  
  29. fillColor
  30. {
  31.     CGRect bounds = self.bounds;
  32.    
  33.     UIGraphicsBeginImageContextWithOptions(CGSizeMake(bounds.size.width + self.lineWidth * 2, bounds.size.width + self.lineWidth * 2),
  34.                                            false, [UIScreen mainScreen].scale);
  35.    
  36.     CGContextRef context = UIGraphicsGetCurrentContext();
  37.    
  38.     // offset the draw to allow the line thickness to not get clipped
  39.     CGContextTranslateCTM(context, self.lineWidth, self.lineWidth);
  40.    
  41.     if (!strokeColor)
  42.     {
  43.         strokeColor = fillColor;
  44.     }
  45.     else
  46.         if (!fillColor)
  47.         {
  48.             fillColor = strokeColor;
  49.         }
  50.    
  51.     [strokeColor setStroke];
  52.     [fillColor setFill];
  53.    
  54.     [self fill];
  55.     [self stroke];
  56.    
  57.     UIImage *result = UIGraphicsGetImageFromCurrentImageContext();
  58.    
  59.     UIGraphicsEndImageContext();
  60.    
  61.     return result;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment