<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Ultie &#187; iphone development</title>
	<atom:link href="http://www.ultie.com/archives/category/iphone-development/feed" rel="self" type="application/rss+xml" />
	<link>http://www.ultie.com</link>
	<description>Use the Little To gEt the bIg</description>
	<lastBuildDate>Mon, 09 May 2011 11:05:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Simple Color Picker Control in IPhone</title>
		<link>http://www.ultie.com/archives/28</link>
		<comments>http://www.ultie.com/archives/28#comments</comments>
		<pubDate>Thu, 25 Jun 2009 13:12:11 +0000</pubDate>
		<dc:creator>Song</dc:creator>
				<category><![CDATA[iphone development]]></category>

		<guid isPermaLink="false">http://www.ultie.com/?p=28</guid>
		<description><![CDATA[ColorPicker.h // // ColorPicker.m // Created by Song on 6/2/09. // Copyright 2009 Ultie. All rights reserved. // #import @interface ColorPicker : UIView { UIView *selectedColorBox; SEL colorChangeSelector; id colorChangeObject; } @property(nonatomic) SEL colorChangeSelector; @property(nonatomic, retain) id colorChangeObject; -(void) onColorChange: (SEL) selector withObject: (id) object; @end ColorPicker.m // // ColorPicker.m // Created by Song on [...]]]></description>
			<content:encoded><![CDATA[<p>ColorPicker.h<br />
//<br />
//  ColorPicker.m<br />
//  Created by Song on 6/2/09.<br />
//  Copyright 2009 Ultie. All rights reserved.<br />
//<br />
<code>#import <uikit/UIKit.h></p>
<p>@interface ColorPicker : UIView {<br />
	UIView *selectedColorBox;<br />
	SEL colorChangeSelector;<br />
	id colorChangeObject;<br />
}</p>
<p>@property(nonatomic) SEL colorChangeSelector;<br />
@property(nonatomic, retain) id colorChangeObject;</p>
<p>-(void) onColorChange: (SEL) selector withObject: (id) object;<br />
@end</code></p>
<p>ColorPicker.m<br />
<code><br />
//<br />
//  ColorPicker.m<br />
//  Created by Song on 6/2/09.<br />
//  Copyright 2009 Ultie. All rights reserved.<br />
//<br />
#import "ColorPicker.h"</p>
<p>@implementation ColorPicker<br />
@synthesize colorChangeSelector;<br />
@synthesize colorChangeObject;</p>
<p>- (id)initWithFrame:(CGRect)frame {<br />
    if (self = [super initWithFrame:frame]) {<br />
        selectedColorBox = [[UIView alloc] initWithFrame: CGRectMake(0, -3, frame.size.height + 6, frame.size.height + 6)];<br />
		selectedColorBox.backgroundColor = [UIColor redColor];<br />
		[self addSubview: selectedColorBox];<br />
    }<br />
    return self;<br />
}</p>
<p>- (void) fill: (float []) color withIndex: (int) i{<br />
	int colors[] = {<br />
		255, 0, 0,<br />
		255, 0, 255,<br />
		0, 0, 255,<br />
		0, 255, 255,<br />
		0, 255, 0,<br />
		255, 255, 0,<br />
		255, 0, 0<br />
	};<br />
	int colorCount = sizeof(colors) / 3 / sizeof(int);<br />
	int p = self.bounds.size.width / (colorCount - 1);<br />
	int r,g,b;<br />
	int ii = i / p;<br />
	int colorA[] = {colors[ii * 3], colors[ii * 3 + 1], colors[ii * 3 + 2]};<br />
	int colorB[] = {colors[(ii + 1) * 3], colors[(ii + 1) * 3 + 1], colors[(ii + 1) * 3 + 2]};</p>
<p>	r = colorA[0] - (colorA[0] - colorB[0])/p * (i % p);<br />
	g = colorA[1] - (colorA[1] - colorB[1])/p * (i % p);<br />
	b = colorA[2] - (colorA[2] - colorB[2])/p * (i % p);<br />
	color[0] = r / 256.0;<br />
	color[1] = g / 256.0;<br />
	color[2] = b / 256.0;<br />
}</p>
<p>- (void)drawRect:(CGRect)rect {<br />
	CGContextRef context = UIGraphicsGetCurrentContext();<br />
	CGContextSaveGState(context);<br />
	CGContextSetLineWidth(context, 1);<br />
	int colors[] = {<br />
		255, 0, 0,<br />
		255, 0, 255,<br />
		0, 0, 255,<br />
		0, 255, 255,<br />
		0, 255, 0,<br />
		255, 255, 0,<br />
		255, 0, 0<br />
	};<br />
	int colorCount = sizeof(colors) / 3 / sizeof(int);<br />
	int p = rect.size.width / (colorCount - 1);<br />
	for(int i = 0; i < rect.size.width; i++){<br />
		int r,g,b;<br />
		int ii = i / p;<br />
		int colorA[] = {colors[ii * 3], colors[ii * 3 + 1], colors[ii * 3 + 2]};<br />
		int colorB[] = {colors[(ii + 1) * 3], colors[(ii + 1) * 3 + 1], colors[(ii + 1) * 3 + 2]};</p>
<p>		r = colorA[0] - (colorA[0] - colorB[0])/p * (i % p);<br />
		g = colorA[1] - (colorA[1] - colorB[1])/p * (i % p);<br />
		b = colorA[2] - (colorA[2] - colorB[2])/p * (i % p);</p>
<p>		//NSLog(@"cc=%d p=%d i=%d ii=%d r=%d g=%d b=%d", colorCount, p, i, ii, r, g, b);<br />
		CGContextSetRGBStrokeColor(context, r/256.0, g/256.0, b/256.0, 1.0);</p>
<p>		CGPoint addLines[] = {<br />
			CGPointMake(i, 0),<br />
			CGPointMake(i, rect.size.height)<br />
		};<br />
		CGContextAddLines(context, addLines, 2);<br />
		CGContextStrokePath(context);<br />
	}</p>
<p>	CGContextRestoreGState(context);<br />
}</p>
<p>- (void)dealloc {<br />
	[selectedColorBox release];<br />
	[colorChangeObject release];<br />
    [super dealloc];<br />
}</p>
<p>- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{<br />
	UITouch *touch = [touches anyObject];<br />
	CGPoint point = [touch locationInView: self];<br />
	float color[] = {0, 0, 0};<br />
	[self fill: color withIndex: point.x];<br />
	UIColor *uc = [[UIColor alloc] initWithRed: color[0] green: color[1] blue: color[2] alpha: 1];<br />
	selectedColorBox.backgroundColor = uc;<br />
	if(colorChangeObject != nil){<br />
		[colorChangeObject methodForSelector: colorChangeSelector](colorChangeObject, colorChangeSelector, uc);<br />
	}<br />
	[uc release];<br />
	selectedColorBox.center = CGPointMake(point.x, self.bounds.size.height/2);</p>
<p>}</p>
<p>- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{<br />
	[self touchesBegan: touches withEvent: event];<br />
}</p>
<p>- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{<br />
	[self touchesBegan: touches withEvent: event];<br />
}</p>
<p>- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event{<br />
	[self touchesBegan: touches withEvent: event];<br />
}</p>
<p>-(void) onColorChange: (SEL) selector withObject: (id) object{<br />
	self.colorChangeSelector = selector;<br />
	self.colorChangeObject = object;<br />
}<br />
@end<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ultie.com/archives/28/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Quit IPhone Application with SDK3.0</title>
		<link>http://www.ultie.com/archives/26</link>
		<comments>http://www.ultie.com/archives/26#comments</comments>
		<pubDate>Thu, 25 Jun 2009 13:05:26 +0000</pubDate>
		<dc:creator>Song</dc:creator>
				<category><![CDATA[iphone development]]></category>

		<guid isPermaLink="false">http://www.ultie.com/?p=26</guid>
		<description><![CDATA[[[UIApplication sharedApplication] terminateWithSuccess]; add below code in .h define in order to ignore compiler warnings: @interface UIApplication (extended) -(void) terminateWithSuccess; @end]]></description>
			<content:encoded><![CDATA[<p>[[UIApplication sharedApplication] terminateWithSuccess];</p>
<p>add below code in .h define in order to ignore compiler warnings:<br />
<code>@interface UIApplication (extended)<br />
-(void) terminateWithSuccess;<br />
@end</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ultie.com/archives/26/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CGImage scale in iphone</title>
		<link>http://www.ultie.com/archives/19</link>
		<comments>http://www.ultie.com/archives/19#comments</comments>
		<pubDate>Thu, 25 Jun 2009 12:39:16 +0000</pubDate>
		<dc:creator>Song</dc:creator>
				<category><![CDATA[iphone development]]></category>

		<guid isPermaLink="false">http://www.ultie.com/?p=19</guid>
		<description><![CDATA[[ Remember to release the return CGImageRef with CGImageRelease() manually! ] 1) scale image with scale rate. +(CGImageRef)scaleCGImage: (CGImageRef) image withScale: (float) scale { // Create the bitmap context CGContextRef context = NULL; void * bitmapData; int bitmapByteCount; int bitmapBytesPerRow; // Get image width, height. We'll use the entire image. int width = CGImageGetWidth(image) * [...]]]></description>
			<content:encoded><![CDATA[<p><strong><font color="#ff0000">[ Remember to release the return CGImageRef with CGImageRelease() manually! ]</font></strong></p>
<p>1) scale image with scale rate.<br />
<code>+(CGImageRef)scaleCGImage: (CGImageRef) image withScale: (float) scale<br />
{<br />
	// Create the bitmap context<br />
	CGContextRef    context = NULL;<br />
	void *          bitmapData;<br />
	int             bitmapByteCount;<br />
	int             bitmapBytesPerRow;</p>
<p>	// Get image width, height. We'll use the entire image.<br />
	int width = CGImageGetWidth(image) * scale;<br />
	int height = CGImageGetHeight(image) * scale;</p>
<p>	// Declare the number of bytes per row. Each pixel in the bitmap in this<br />
	// example is represented by 4 bytes; 8 bits each of red, green, blue, and<br />
	// alpha.<br />
	bitmapBytesPerRow   = (width * 4);<br />
	bitmapByteCount     = (bitmapBytesPerRow * height);</p>
<p>	// Allocate memory for image data. This is the destination in memory<br />
	// where any drawing to the bitmap context will be rendered.<br />
	bitmapData = malloc( bitmapByteCount );<br />
	if (bitmapData == NULL)<br />
	{<br />
		return nil;<br />
	}</p>
<p>	// Create the bitmap context. We want pre-multiplied ARGB, 8-bits<br />
	// per component. Regardless of what the source image format is<br />
	// (CMYK, Grayscale, and so on) it will be converted over to the format<br />
	// specified here by CGBitmapContextCreate.<br />
	CGColorSpaceRef colorspace = CGImageGetColorSpace(image);<br />
	context = CGBitmapContextCreate (bitmapData,width,height,8,bitmapBytesPerRow,<br />
									 colorspace,kCGImageAlphaPremultipliedFirst);<br />
	CGColorSpaceRelease(colorspace);</p>
<p>	if (context == NULL)<br />
		// error creating context<br />
		return nil;</p>
<p>	// Draw the image to the bitmap context. Once we draw, the memory<br />
	// allocated for the context for rendering will then contain the<br />
	// raw image data in the specified color space.<br />
	CGContextDrawImage(context, CGRectMake(0,0,width, height), image);</p>
<p>	CGImageRef imgRef = CGBitmapContextCreateImage(context);<br />
	CGContextRelease(context);<br />
	free(bitmapData);</p>
<p>	return imgRef;<br />
}</code></p>
<p>2) Scale image with size and rotation<br />
<code><br />
+(CGImageRef)scaleCGImage: (CGImageRef) image withPrefix: (CGSize) size withRotation: (float) rotation<br />
{<br />
	CGContextRef    context = NULL;<br />
	void *          bitmapData;<br />
	int             bitmapByteCount;<br />
	int             bitmapBytesPerRow;</p>
<p>	int width = size.width;<br />
	int height = size.height;</p>
<p>	bitmapBytesPerRow   = (width * 4);<br />
	bitmapByteCount     = (bitmapBytesPerRow * height);</p>
<p>	bitmapData = malloc( bitmapByteCount );<br />
	if (bitmapData == NULL)<br />
	{<br />
		return nil;<br />
	}<br />
	memset(bitmapData, 0, bitmapByteCount);<br />
	CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();<br />
	context = CGBitmapContextCreate (bitmapData,width,height,8,bitmapBytesPerRow,<br />
									 colorspace,kCGImageAlphaPremultipliedFirst);<br />
	CGColorSpaceRelease(colorspace);</p>
<p>	if (context == NULL)<br />
		return nil;</p>
<p>	if(rotation != 0){<br />
		CGAffineTransform  tran = CGAffineTransformIdentity;<br />
		tran = CGAffineTransformMakeRotation(rotation);<br />
		CGContextConcatCTM(context, tran);<br />
		CGContextDrawImage(context, CGRectMake(10, 10, width - 20, height - 20), image);<br />
	}else{<br />
		CGContextDrawImage(context, CGRectMake(0, 0, width, height), image);<br />
	}<br />
	CGImageRef imgRef = CGBitmapContextCreateImage(context);<br />
	CGContextRelease(context);<br />
	free(bitmapData);</p>
<p>	return imgRef;<br />
}<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ultie.com/archives/19/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

