WKWebView ScaleToFit

时间:2016-02-23 04:30:16

标签: ios iphone ios9 wkwebview

从UIWebView移动到WKWebView,我无法弄清楚如何使用WKWebView大小的loadHTMLString函数来加载我正在加载的HTML以适应视图边界。我现在得到html加载,但它在我的视图的右侧和底部。如何缩放它以适合我的视图范围?

1 个答案:

答案 0 :(得分:6)

首先,在 StoryBoard 中获取容器视图,在该视图下,您要将WKWebView添加为子视图

import os
import sys
import shutil
import zipfile
import traceback

print ('Welcome to USB Backup Utility')
print ('Created by: TheCryptek')
print ('\nWhat directory would you like to back up?')
print ('Example: C:/users/user/Desktop/Folder')
backUp = raw_input('> ') # Files the user specified to back up
print ('\nWhere would you like to back these files up at?')
print ('Example USB Letter: E:/')
backDevice = raw_input('> ') # Device the user specified to save the back up on.
print ('\nName of the zip file you prefer?')
print ('Example: Backup.zip')
backZip = raw_input('> ') # The name of the zip file specified by the user
print ('\nBackup started...')
if not os.path.exists(backDevice + '/BackUp'): # If the BackUp folder doesn't exist on the device then
    os.mkdir(backDevice + 'BackUp') # Make the backup folder on usb device
backZip = zipfile.ZipFile(backZip, 'w') # Not sure what to say for lines 21 - 26
for dirname, subdirs, files in os.walk(backUp): 
    backZip.write(dirname)
    for filename in files:
        backZip.write(os.path.join(dirname, filename))
    backZip.close()
shutil.move(backZip, backDevice + '/BackUp') # Move the zip files created in working directory to the specified back up device -[ Something is wrong with this can't figure out what ]-
print('Backup finished.')

然后导入 WebKit 并初始化它,然后添加为容器的子视图。为了保留边界,您必须根据其父视图为其赋予约束值。我就是这样做的:

@IBOutlet var container: UIView!

添加所需的网址,您就完成了。