I am trying to write a function to convert the textfield text to an image (example). I have tried to search for an example, most of the sample also is overwrite text on imag
You could try creating your own custom UIView subclass, drawing an NSString on it (your text), then converting that to a UIImage. You can draw text on a UIView only in the -drawRect: method. Here is an idea for your subclass.
@interface TextView : UIView {
NSString *_text;
}
- (id)initWithFrame:(CGRect)frame andText:(NSString *)text;
@end
@implementation TextView
- (id)initWithFrame:(CGRect)frame andText:(NSString *)text
{
if (self = [super initWithFrame:frame]) {
_text = text;
}
[self setNeedsDisplay]; // calls the -drawRect method
return self;
}
- (void)drawRect:(CGRect)rect
{
[_text drawAtPoint:/* location of text*/
withAttributes:/* style of text*/];
}
More information about drawing NSStrings can be found here. Once you have this view with your text on it, convert it to a UIImage with this technique.