关于截屏今天在这里总结一下
- 如何截取状态栏
- 如何截取除状态栏之外的屏幕
- 如何截取整个屏幕
截取状态栏
很多人想截取整个屏幕,但是总是截取不到状态栏,那么我们就先来看看如何只截取状态栏,我把它分为两个步骤
-
获取到状态栏
UIApplication * app = [UIApplication sharedApplication]; UIView *statusBar = [app valueForKey:@"_statusBar"];
-
截取
UIGraphicsBeginImageContext(statusBar.frame.size); [statusBar drawViewHierarchyInRect:statusBarview.bounds afterScreenUpdates:YES]; UIImage *image = [UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext();
截取除状态栏之外的屏幕
截取
```
- (UIImage *)snapshot:(UIView *)view
{
UIGraphicsBeginImageContext(view.frame.size);
[view drawViewHierarchyInRect:view.bounds afterScreenUpdates:YES];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
这里只需传入`self.view`就可以了
## 截取整个屏幕
有了前面两个,我想第三个问题就迎刃而解了吧,这里给个提示,可以分别截取后把两张图片合成一个。