CGRect backRect = CGRectMake(10, 10, 50, 8);
CGContextSetRGBFillColor(context, 1.0, 1.0, 1.0, 1.0);
CGContextFillRect(context, backRect);
CGContextTranslateCTM(context, 0.0, self.frame.size.height);
CGContextScaleCTM(context, 1.0, -1.0);
CGContextShowTextAtPoint 不能draw中文,中文等UTF8 需要用
- (void)drawRect:(CGRect)rect {
// Drawing code
CGRect myrect;
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSaveGState(context);
//CGContextSetAllowsAntialiasing(context,true);
CGContextTranslateCTM(context, 0.0, self.frame.size.height);
CGContextScaleCTM(context, 1.0, -1.0);
for (NSNumber *number in data) {
int x = [number intValue] * CGImageGetWidth(cards)/5;
if (x >320-CGImageGetWidth(cards)/5) {
myrect=CGRectMake(x-(320-CGImageGetWidth(cards)/5) , CGImageGetHeight(cards),CGImageGetWidth(cards)/5, CGImageGetHeight(cards));
} else {
myrect=CGRectMake(x-20*[number intValue] ,0 , CGImageGetWidth(cards)/5,CGImageGetHeight(cards));
}
CGImageRef tmp = CGImageCreateWithImageInRect(cards,CGRectMake([number intValue] * (CGImageGetWidth(cards)/5), 0, CGImageGetWidth(cards)/5, CGImageGetHeight(cards) ));
CGImageRef digit = CGImageCreateWithImageInRect(digits,CGRectMake([number intValue] *CGImageGetWidth(digits)/13, CGImageGetHeight(digits)/2, CGImageGetWidth(digits)/13,CGImageGetHeight(digits)/2 ));
CGContextDrawImage(context,myrect,tmp);
CGRect digrect = CGRectMake(myrect.origin.x + 2, CGImageGetHeight(cards) -CGImageGetHeight(digits)/2 -3,CGImageGetWidth(digits)/13, CGImageGetHeight(digits)/2);
NSLog(@"%f",myrect.origin.x );
CGContextDrawImage(context,digrect,digit);
CGImageRef chip = CGImageCreateWithImageInRect(chips,CGRectMake(3*CGImageGetWidth(chips)/4, 0, CGImageGetWidth(chips)/4, CGImageGetHeight(chips)));
for (int i=0; i<10; i++) {
CGContextDrawImage(context,CGRectMake(0, CGImageGetHeight(cards)+6*i,0.6*CGImageGetWidth(chips)/4, 0.6*CGImageGetHeight(chips)),chip);
CGContextDrawImage(context,CGRectMake(0.6*CGImageGetWidth(chips)/4,CGImageGetHeight(cards)+6*i, 0.6*CGImageGetWidth(chips)/4, 0.6*CGImageGetHeight(chips)),chip);
}
CGContextSelectFont(context, "Helvetica", 20,
kCGEncodingMacRoman);
CGContextSetTextDrawingMode(context, kCGTextFill);
CGContextSetRGBFillColor (context, 0, 1, 0, .5); // 6
//CGContextSetRGBStrokeColor (context, 0, 0, 1, 1);
CGContextShowTextAtPoint(context,0,2*CGImageGetHeight(cards)+6*10,"$234",4);
CGContextShowTextAtPoint(context,0,2*CGImageGetHeight(cards)+6*10+20,"Will",4);
//CFRelease(tmp);
//CFRelease(digit);
}
if (newRound == NO) {
CGRect backRect = CGRectMake(10, 10, 50, 8);
CGContextSetRGBFillColor(context, 1.0, 1.0, 1.0, 1.0);
CGContextFillRect(context, backRect);
CGRect ourRect;
// Set the fill color to opaque red.
CGContextSetRGBFillColor(context, 1.0, 0.0, 0.0, 1.0);
// Set up the rectangle for drawing.
ourRect.origin.x = ourRect.origin.y = 10.0;
ourRect.size.width = Height;
ourRect.size.height = 8.0;
// Draw the filled rectangle.
CGContextFillRect(context, ourRect);
backRect = CGRectMake(110, 110, 50, 8);
CGContextSetRGBFillColor(context, 1.0, 1.0, 1.0, 1.0);
CGContextFillRect(context, backRect);
//CGRect ourRect;
// Set the fill color to opaque red.
CGContextSetRGBFillColor(context, 1.0, 0.0, 0.0, 1.0);
// Set up the rectangle for drawing.
ourRect.origin.x = ourRect.origin.y = 110.0;
ourRect.size.width = Height;
ourRect.size.height = 8.0;
// Draw the filled rectangle.
CGContextFillRect(context, ourRect);
}
CGContextRestoreGState(context);
CGContextSetRGBFillColor(context, 1.0, 1.0, 1.0, 1.0);
[@"孔祥波" drawAtPoint:CGPointMake(0,320-(2*CGImageGetHeight(cards)+6*10+60)) withFont:[UIFontfontWithName:@"Helvetica-Bold" size:20]];
}