ios 给图片加文字

- (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;

}

你可能感兴趣的:(ios 给图片加文字)