gpt4 book ai didi

iphone - 如何在UIWebview中心加载pdf文件

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:20:40 24 4
gpt4 key购买 nike

我是 ios developement 的新手。我正在尝试在 UIWebview 中心显示 pdf。我在 mainbundle 中有一个 pdf。这是我的 PDF 在 UIWebView 中加载时的样子:(我放入了棕色渐变作为 UIWebView 的背景,所以你可以更好地理解我的意思)。 enter image description here

- (void)viewDidLoad
{
UIWebView *theWebView = [[UIWebView alloc] initWithFrame:[self.view bounds]];
[theWebView setContentMode:UIViewContentModeScaleAspectFit];
[theWebView setAutoresizingMask:UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth];
[theWebView setScalesPageToFit:YES];
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"pdf"];
NSURL *filePathURL = [NSURL fileURLWithPath:filePath];
[theWebView loadRequest:[NSURLRequest requestWithURL:filePathURL]];

[self.view addSubview:theWebView];
[super viewDidLoad];
}

我想将其居中,以便底部边距与顶部边距相同。我如何使用 PDF(本地)执行此操作?

最佳答案

CGRect rect = [[UIScreen mainScreen] bounds];
CGSize screenSize = rect.size;
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0,0,screenSize.width,screenSize.height)];

NSString *path = [[NSBundle mainBundle] pathForResource:@"pdf" ofType:@"pdf"];
NSURL *targetURL = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
[webView loadRequest:request];

[self.view addSubview:webView];

关于iphone - 如何在UIWebview中心加载pdf文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18653907/

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