Not much to say, directly on the code
A new class of UIImage, declared in. h
+ (UIImage *) Imagewithimage: (uiimage *) image content: (NSString *) content frame: (cgrect) frame;
. m below
+ (UIImage *) Imagewithimage: (uiimage *) image content: (NSString *) content frame: (CGRect) Frame {
//Open Graphics ' context '
Uigraphicsbeginimagecontextwithoptions (image.size, NO, 0);
Draw native Pictures
[image Drawatpoint:cgpointzero];
Draw the text
nsstring *str = content on the native graph;
Create a dictionary of text properties
nsdictionary *dictionary = @{nsforegroundcolorattributename: [Uicolor Blackcolor], Nsfontattributename: [Uifont systemfontofsize:20]};
Draw text Attributes
[str drawinrect:frame withattributes:dictionary];
Gets the modified picture from the current context
uiimage *imagenew = Uigraphicsgetimagefromcurrentimagecontext ();
End Graphics Context
uigraphicsendimagecontext ();
return imagenew;
}
but it is to be drawInRect: withAttributes: noted that The method can be used after iOS7.0, when using this method , it is necessary to see whether the system is appropriate or to add judgment to the method.
Double device = [[Uidevice currentdevice].systemversion doublevalue];
if (device >= 7.0f) {
//do something
}
Then import the header file in VC, create a ImageView
Call method to pass in an Image object, the text and text you want to add
uiimage *image = [UIImage imagewithimage:[uiimage imagenamed:@ "3"] content:@ " Illidan "Frame: CGRectMake (M, M, M )];
Uiimageview *imageview = [[Uiimageview alloc]initwithframe:cgrectmake (0, 0, Kscreenwidth, kscreenheight)];
Imageview.image = image;
[Self.view Addsubview:imageview];
The effect of the following figure, the simple implementation of the image watermark on the function, if you want to change the size of text and color can be modified in the method. Or add a dictionary parameter to the method for a text attribute.
The above is in the iOS to the picture watermark all content, this article has given the example code, believed to everybody understanding to be helpful, hoped that can develop the iOS to be helpful to everybody.