如何给一个ScrollView添加一个水印, 或者添加一些文字或截图
-
(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
CGSize scrollViewSize = CGSizeMake(self.scrollView.frame.size.width, self.scrollView.frame.size.height);
// 1. 开启位图上下文
UIGraphicsBeginImageContextWithOptions(scrollViewSize, 0, 1);// 2. 获取当前的内容
[self.scrollView.layer renderInContext:UIGraphicsGetCurrentContext()];// 3. 创建文字添加到上下文
NSString *string = @"我是水印";
[string drawAtPoint:CGPointMake(50, 50) withAttributes:nil];// 3.2 添加一个图片
UIImage *image = [UIImage imageNamed:@"current"];
[image drawAtPoint:CGPointMake(0, 0)];// 4. 生成图片
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();// 5. 关闭图形上下文
UIGraphicsEndImageContext();// 6. 设置图片
UIImageView *imageView = [[UIImageView alloc] init];
imageView.frame = CGRectMake(0, 0, scrollViewSize.width, scrollViewSize.height);imageView.image = newImage;
[self.view addSubview:imageView];
}
网友评论