// // TutorialBubble.m // Cart Collect // // Created by Starla Insigna on 8/4/11. // Copyright 2011 Four Island. All rights reserved. // #import "TutorialBubble.h" @implementation TutorialBubble @synthesize name; - (id)initWithText:(NSString*)text name:(NSString*)m_name { self = [super init]; textView = [[UILabel alloc] init]; textView.text = text; textView.font = [UIFont systemFontOfSize:14.0f]; CGSize size = [textView.text sizeWithFont:textView.font constrainedToSize:CGSizeMake(200, 300) lineBreakMode:UILineBreakModeWordWrap]; textView.lineBreakMode = UILineBreakModeWordWrap; textView.numberOfLines = 0; textView.frame = CGRectMake(8, 8, size.width, size.height); button = [UIButton buttonWithType:UIButtonTypeCustom]; [button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside]; CGImageRef framestuff = [[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"framestuff" ofType:@"png"]] CGImage]; CGImageRef topLeftRef = CGImageCreateWithImageInRect(framestuff, CGRectMake(0, 0, 8, 8)); CGImageRef topRightRef = CGImageCreateWithImageInRect(framestuff, CGRectMake(8, 0, 8, 8)); CGImageRef bottomLeftRef = CGImageCreateWithImageInRect(framestuff, CGRectMake(0, 8, 8, 8)); CGImageRef bottomRightRef = CGImageCreateWithImageInRect(framestuff, CGRectMake(8, 8, 8, 8)); CGImageRef topBorderRef = CGImageCreateWithImageInRect(framestuff, CGRectMake(0, 16, 8, 8)); CGImageRef leftBorderRef = CGImageCreateWithImageInRect(framestuff, CGRectMake(8, 16, 8, 8)); CGImageRef rightBorderRef = CGImageCreateWithImageInRect(framestuff, CGRectMake(0, 24, 8, 8)); CGImageRef bottomBorderRef = CGImageCreateWithImageInRect(framestuff, CGRectMake(8, 24, 8, 8)); UIImage* topLeft = [UIImage imageWithCGImage:topLeftRef]; UIImage* topRight = [UIImage imageWithCGImage:topRightRef]; UIImage* bottomLeft = [UIImage imageWithCGImage:bottomLeftRef]; UIImage* bottomRight = [UIImage imageWithCGImage:bottomRightRef]; UIImage* topBorder = [UIImage imageWithCGImage:topBorderRef]; UIImage* leftBorder = [UIImage imageWithCGImage:leftBorderRef]; UIImage* rightBorder = [UIImage imageWithCGImage:rightBorderRef]; UIImage* bottomBorder = [UIImage imageWithCGImage:bottomBorderRef]; CGImageRelease(topLeftRef); CGImageRelease(topRightRef); CGImageRelease(bottomLeftRef); CGImageRelease(bottomRightRef); CGImageRelease(topBorderRef); CGImageRelease(leftBorderRef); CGImageRelease(rightBorderRef); CGImageRelease(bottomBorderRef); CGSize boxSize = CGSizeMake(size.width, size.height); UIGraphicsBeginImageContext(CGSizeMake(boxSize.width+16, boxSize.height+16)); CGContextRef context = UIGraphicsGetCurrentContext(); UIGraphicsPushContext(context); [topLeft drawInRect:CGRectMake(0, 0, 8, 8)]; [topBorder drawInRect:CGRectMake(8, 0, boxSize.width, 8)]; [topRight drawInRect:CGRectMake(8+boxSize.width, 0, 8, 8)]; [rightBorder drawInRect:CGRectMake(8+boxSize.width, 8, 8, boxSize.height)]; [bottomRight drawInRect:CGRectMake(8+boxSize.width, 8+boxSize.height, 8, 8)]; [bottomBorder drawInRect:CGRectMake(8, 8+boxSize.height, boxSize.width, 8)]; [bottomLeft drawInRect:CGRectMake(0, 8+boxSize.height, 8, 8)]; [leftBorder drawInRect:CGRectMake(0, 8, 8, boxSize.height)]; CGContextSetFillColorWithColor(context, [[UIColor whiteColor] CGColor]); CGContextFillRect(context, CGRectMake(8, 8, boxSize.width, boxSize.height)); UIGraphicsPopContext(); background = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); imageView = [[UIImageView alloc] initWithImage:background]; [imageView setFrame:CGRectMake(0, 0, boxSize.width+16, boxSize.height+16)]; [button addSubview:imageView]; [button addSubview:textView]; button.frame = CGRectMake(0, 0, boxSize.width+16, boxSize.height+16); [self addSubview:button]; self.frame = CGRectMake(240-(boxSize.width+16)/2, 160-(boxSize.height+16)/2, boxSize.width+16, boxSize.height+16); name = [m_name retain];
name: "Purple Planet"