I have a textbox, where i want the written text to be added to a UIImage.
How can i draw NSString to a UIImage?
I´ve searched, and found lots of examples, but non of them works. Xcode just gives me lots of errors.
Simply put, i want to draw a NSString to a UIimage. The UIImage should be the same size as a predefined UIImageView, and be placed in center.
Any ideas?
UIImage is not a subview of UIView, so you cant add a subview to it. Also NSString is not a subview of UIView. If you want to show things on the screen, they should inherit from UIView.
So try this:
Create a UIImageView - set its image property to be your UIImage instance.
Create a UILabel - set its text property to your NSString.
Add the UILabel as a subview of your UIImageView.
and finally add your UIImageView to your current view controllers view.
Emm, here is some thoughts. I think that one simple way is like this :
This may works fine.
Also, this may come with a problem that screenshot may be not clear. Then, After step1 and step2, we may get new image by UIGraphics. (With here, we already know position where text should be on image and this should be ok.)
PS: Some image may not have some attribution like CGImage and CGImage is needed for this. So, transform it.
i think solution is here..i have used this method in one of my application here lbltext is the object of my label. this method creates new image with given text & return the object of new image with text.
in your below comment you have passed iv.center as a point.. try manualy like this
you have to call above method like this...
here,img is another instace of UIImage for storing new image with text...after calling this method use img imager for your further use..
for example...
i hope this will help you