title: iOS SDK Write on UIImage draw text
body: <p>Code to write text on image:</p>
  
  <pre><code>-(UIImage *)addText:(UIImage *)img text:(NSString *)text1
  {
      int w = img.size.width;
      int h = img.size.height; 
      CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
      CGContextRef context = CGBitmapContextCreate(NULL, w, h, 8, 4 * w, colorSpace, kCGImageAlphaPremultipliedFirst);
  
      CGContextDrawImage(context, CGRectMake(0, 0, w, h), img.CGImage);
      CGContextSetRGBFillColor(context, 0.0, 0.0, 1.0, 1);
  
      char* text = (char *)[text1 cStringUsingEncoding:NSASCIIStringEncoding];
      CGContextSelectFont(context, "Arial", 18, kCGEncodingMacRoman);
      CGContextSetTextDrawingMode(context, kCGTextFill);
  
      CGContextSetRGBFillColor(context, 255, 255, 255, 2);
  
      CGContextShowTextAtPoint(context, 10, 170, text, strlen(text));
  
      CGImageRef imageMasked = CGBitmapContextCreateImage(context);
      CGContextRelease(context);
      CGColorSpaceRelease(colorSpace);
  
      return [UIImage imageWithCGImage:imageMasked];
  }
  </code></pre>
  
  <p>And improve with this action:</p>
  
  <pre><code>- (IBAction)drawImage:(id)sender {
      NSString *text1 = myTextField.text;
      UIImage *updatedImg = [self addText:myImageView.image text:text1]; 
      [myImageView setImage: updatedImg];
  }
  </code></pre>
  
  <p>It working good, after i create a ColorPicker for myTextField, now i can choose the color of my textField.</p>
  
  <p>How can use the same color of myTextField in the first code above?</p>
  
  <pre><code>//this is the code color for drawing text    
  
  CGContextSetRGBFillColor(context, 255, 255, 255, 2);
  
  //how can change this to get the color by myTextField?
  </code></pre>
  
  <p>any one can help me please.</p>
  
  <p>thx.</p>
  
  <p>//--------------------------------------------------------------------------------</p>
  
  <p>Hello, please i needed the solution :(</p>
  
  <p>Try to explain better:</p>
  
  <p>In conclusion i will pick the color information by <code>myTextField.textColor</code> and report inside the <code>UIImage</code> code to do a color text on image.</p>
  
  <p>Thx.</p>