I want to make an image like this programmatically:
I have the upper image and text with me. Should I write text on the image?
I want to make it a complete .png image(image + label) and set it as the background of the button.
I want to make an image like this programmatically:
I have the upper image and text with me. Should I write text on the image?
I want to make it a complete .png image(image + label) and set it as the background of the button.
Here is the Swift version.
To call it you just pass in an image.
The following links helped me get this straight.
Swift - Drawing text with drawInRect:withAttributes:
How to write text on image in Objective-C (iOS)?
The original goal was to create a dynamic image that I could use in an AnnotaionView such as putting a price at a given location on a map and this worked out great for it. Hope this helps someone trying to do the same thing.
Swift 3
My function can add text water mark on image with 45 degree and 90 degree rotations
Enum for rotation:
Note: Use 0 for drawing watermark in centre of image.(Default case of switch statement)
Add this macro for degree to radian:
Hope this helps !!!
Set the frame of the label where you want the label to be displayed.
Draw text inside an image and return the resulting image:
Usage:
Change the origin of the text inside the image from 0,0 to whatever point you like.
To paint a rectangle of solid color behind the text, add the following before the line
[[UIColor whiteColor] set];
:I'm using the text size to calculate the origin for the solid color rectangle, but you can replace it with any number.
Here is a Swift version which correctly centers the text on the image. This works with text of various sizes.