Take the 2-minute tour ×

My iOS app needs to be able to generate an image to post to Facebook and Twitter. The image will be a representation of data added by the user. The image is not a direct representation of any view that will be displayed on screen. It is not necessary to include any other image resources in the image created - for the most part I need to format the style and layout some text, and maybe add some borders, lines, etc - but I would like the ability to add this later if it is simple.

What approach is best for something like this? Should I build a UIView and output it to a file somehow? Is there an HTML/CSS solution? Or some other approach?

Bonus points if you can recommend the file format and attributes optimized for posting to Facebook/Twitter.

share|improve this question

1 Answer 1

Use UIGraphicsBeginImageContextWithOptions() to create a new image context.

Then, draw whatever you like into it using Core Graphics. You can draw text using Core Graphics or Core Text — the former is easier, but the latter gives you more opportunity for customisation.

Then, get a UIImage out of your context by using UIGraphicsGetImageFromCurrentImageContext().

You can then convert the UIImage into a PNG using UIImagePNGRepresentation().

share|improve this answer
Thanks Amy. 'The Core Graphics framework is a C-based API...' - I might see if there are some suggestions that better match my skill set before embarking on this approach, but in the meantime will investigate. –  Ben Packard Jan 7 '13 at 18:22

Your Answer


