Sophie

Sophie

distrib > Fedora > 18 > x86_64 > by-pkgid > 8c86774a3e53d77cc119f53a2b94a57a > files > 298

root-tutorial-5.34.14-2.fc18.noarch.rpm

#import <cassert>

#import <QuartzCore/QuartzCore.h>

#import "LineWidthCell.h"

@implementation LineWidthCell {
   CGFloat lineWidth;
}

//____________________________________________________________________________________________________
- (instancetype) initWithFrame : (CGRect) frame width : (CGFloat) w
{
   assert(w >= 0.f && "initWithFrame:width:, parameter 'w' is negative");

   if (self = [super initWithFrame : frame]) {
      lineWidth = w;
      
      self.layer.shadowOpacity = 0.4f;
      self.layer.shadowColor = [UIColor darkGrayColor].CGColor;
      self.layer.shadowOffset = CGSizeMake(4.f, 4.f);

      self.opaque = NO;
   }

   return self;
}

//____________________________________________________________________________________________________
- (void) drawRect : (CGRect) rect
{
   CGContextRef ctx = UIGraphicsGetCurrentContext();

   //Draw the line.
   CGContextSetLineCap(ctx, kCGLineCapRound);
   CGContextSetLineWidth(ctx, lineWidth);
   CGContextSetRGBStrokeColor(ctx, 0.f, 0.f, 0.f, 1.f);
   CGContextBeginPath(ctx);
   CGContextMoveToPoint(ctx, 10.f, rect.size.height / 2);
   CGContextAddLineToPoint(ctx, rect.size.width - 10, rect.size.height / 2);
   CGContextStrokePath(ctx);
   
   NSString * const label = [NSString stringWithFormat : @"(%d)", (int)lineWidth];
   NSDictionary * const attributes = @{NSFontAttributeName : [UIFont systemFontOfSize : 10],
                                       NSForegroundColorAttributeName : [UIColor blackColor]};
   [label drawInRect : CGRectMake(rect.size.width / 2 - 10.f, rect.size.height / 2 - 15.f, 40.f, 60.f) withAttributes : attributes];
}

//____________________________________________________________________________________________________
- (void) setLineWidth : (CGFloat) width
{
   assert(lineWidth > 0.f && "setLineWidth:, parameter 'width' must be a positive number");

   lineWidth = width;
}

@end