gpt4 book ai didi

ios - 空气打印 View

转载 作者:行者123 更新时间:2023-11-28 22:22:45 26 4
gpt4 key购买 nike

我正在使用 xcode 5。我想知道如何打印当前 View 。因此,一个简单的按钮,上面写着“打印”,然后当用户点击它时,它会在屏幕上打印所有内容。我将如何实现?

最佳答案

截取 View

并在路径中另存为png并将数据传递给UIPrintInteractionController

截图

UIGraphicsBeginImageContextWithOptions(self.view.frame.size, NO, 0.0);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

CGRect rect=self.view.frame;


CGImageRef cropped1 = CGImageCreateWithImageInRect(viewImage.CGImage, rect);
UIImage *imges = [UIImage imageWithCGImage:cropped1];
CGImageRelease(cropped1);
// squarecropimg.image=imges;

NSData *date=UIImagePNGRepresentation(imges);
NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *doc=[paths objectAtIndex:0];
NSString *appstr=[doc stringByAppendingPathComponent:@“currentview.png"];

[日期 writeToFile:appstr 原子地:YES];

将CURRENTVIEW.PNG的数据传给打印机

关于ios - 空气打印 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19877008/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com