- (UIImage*) drawText:(NSString*)text inImage:(UIImage*)image

{

  //prepare image context

  UIGraphicsBeginImageContext(image.size);

  //draw image, (画图片)

  [image drawInRect:CGRectMake(0, 0, image.size.width, image.size.height)];

 

  //set text attributes (font, color, etc)

  UIFont *textFont = [UIFont boldSystemFontOfSize:17.];

  UIColor *textColor = [UIColor whiteColor];

  NSDictionary *attributeDict = @{NSFontAttributeName:textFont, NSForegroundColorAttributeName:textColor};

  //draw text (画文字)

  [text drawInRect:CGRectMake(0, 0, image.size.width, image.size.height) withAttributes:attributeDict];

  //get image from current image context

  UIImage *editedImage = UIGraphicsGetImageFromCurrentImageContext();

  

  UIGraphicsEndImageContext();

  return editedImage;

}

posted on 2015-09-09 14:05  ximenchuixie  阅读(234)  评论(0编辑  收藏  举报