1.代码很简单,主要是要注意配色问题(比如说黑色背景就用白色水印,白色就用黑色)
上代码
//添加水印,返回一个和屏幕等大的水印
+ (UIImageView *)addWatermark
{
static UIImageView * imageView = nil;
if (imageView) {
[imageView removeFromSuperview];
return imageView;
}
NSString *str = @"wangyebin";
if ([str isEqualToString:@""]) {
return nil;
}
CGSize size = [UIScreen mainScreen].bounds.size;
UIGraphicsBeginImageContext(size);
[str drawInRect:CGRectMake(10, 20, size.width, 50) withAttributes:@{NSFontAttributeName:[UIFont fontWithName:@"Marker Felt" size:30],NSForegroundColorAttributeName:[UIColor colorWithRed:1 green:1 blue:1 alpha:1]}];
[str drawInRect:CGRectMake(10, size.height/2, size.width, 50) withAttributes:@{NSFontAttributeName:[UIFont fontWithName:@"Marker Felt" size:30],NSForegroundColorAttributeName:[UIColor colorWithRed:0 green:0 blue:0 alpha:0.8]}];
[str drawInRect:CGRectMake(10, size.height-50, size.width, 50) withAttributes:@{NSFontAttributeName:[UIFont fontWithName:@"Marker Felt" size:30],NSForegroundColorAttributeName:[UIColor colorWithRed:1 green:1 blue:0 alpha:0.8]}];
//返回绘制的新图形
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
imageView = [[UIImageView alloc]initWithFrame:[UIScreen mainScreen].bounds];
imageView.image = newImage;
imageView.alpha = 0.005;
return imageView;
}
原创: 转载请注明出处 http://www.jianshu.com/p/ba9bf641dafc