添加人眼看不出来,但是经过颜色处理后可以看出来的水印

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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容