Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 1st, 2012  |  syntax: None  |  size: 1.71 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. iPad Memory Limitations
  2. - (void)drawRect:(CGRect)rect {
  3.     // get the contect
  4.     CGContextRef context = UIGraphicsGetCurrentContext();
  5.  
  6.     //for the shadow, save the state then draw the shadow
  7.     CGContextSaveGState(context);
  8.     CGContextSetShadow(context, CGSizeMake(4,-5), 10);
  9.  
  10.     //now draw the rounded rectangle
  11.     CGContextSetStrokeColorWithColor(context, [[UIColor blackColor] CGColor]);  
  12.  
  13.     if(_HighlightColor==nil){
  14.         _HighlightColor = [[UIColor whiteColor] retain];
  15.     }
  16.     CGContextSetFillColorWithColor(context, _HighlightColor.CGColor);
  17.  
  18.     //since I need room in my rect for the shadow, make the rounded rectangle a little smaller than frame
  19.     CGRect rrect = CGRectMake(CGRectGetMinX(rect), CGRectGetMinY(rect), CGRectGetWidth(rect)-30, CGRectGetHeight(rect)-30);
  20.     CGFloat radius = 5;
  21.     // the rest is pretty much copied from Apples example
  22.     CGFloat minx = CGRectGetMinX(rrect), midx = CGRectGetMidX(rrect), maxx = CGRectGetMaxX(rrect);
  23.     CGFloat miny = CGRectGetMinY(rrect), midy = CGRectGetMidY(rrect), maxy = CGRectGetMaxY(rrect);
  24.  
  25.     // Start at 1
  26.     CGContextMoveToPoint(context, minx, midy);
  27.     // Add an arc through 2 to 3
  28.     CGContextAddArcToPoint(context, minx, miny, midx, miny, radius);
  29.     // Add an arc through 4 to 5
  30.     CGContextAddArcToPoint(context, maxx, miny, maxx, midy, radius);
  31.     // Add an arc through 6 to 7
  32.     CGContextAddArcToPoint(context, maxx, maxy, midx, maxy, radius);
  33.     // Add an arc through 8 to 9
  34.     CGContextAddArcToPoint(context, minx, maxy, minx, midy, radius);
  35.     // Close the path
  36.     CGContextClosePath(context);
  37.     // Fill & stroke the path
  38.     CGContextDrawPath(context, kCGPathFillStroke);
  39.  
  40.     //for the shadow
  41.     CGContextRestoreGState(context);
  42. }