作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
从 UIWebView 移动到 WKWebView,我不知道如何使用 WKWebView 大小上的 loadHTMLString 函数来制作我正在加载的 HTML 以适应 View 边界。我现在加载了 html,但它超出了我 View 的右侧和底部。如何缩放它以适合我的 View 范围?
最佳答案
首先,在 StoryBoard 中创建一个容器 View ,您将在该 View 下添加 WKWebView 作为一个 subview :
@IBOutlet var container: UIView!
然后导入WebKit并初始化它,稍后添加为容器的 subview 。为了保留边界,您必须根据其父 View 为其赋予约束值。我是这样做的:
let webView = WKWebView(frame: .zero)
container.addSubview(webView)
webView.translatesAutoresizingMaskIntoConstraints = false
let height = NSLayoutConstraint(item: webView, attribute: .height, relatedBy: .equal, toItem: container, attribute: .height, multiplier: 1, constant: 0)
let width = NSLayoutConstraint(item: webView, attribute: .width, relatedBy: .equal, toItem: container, attribute: .width, multiplier: 1, constant: 0)
let leftConstraint = NSLayoutConstraint(item: webView, attribute: .leftMargin, relatedBy: .equal, toItem: container, attribute: .leftMargin, multiplier: 1, constant: 0)
let rightConstraint = NSLayoutConstraint(item: webView, attribute: .rightMargin, relatedBy: .equal, toItem: container, attribute: .rightMargin, multiplier: 1, constant: 0)
let bottomContraint = NSLayoutConstraint(item: webView, attribute: .bottomMargin, relatedBy: .equal, toItem: container, attribute: .bottomMargin, multiplier: 1, constant: 0)
container.addConstraints([height, width, leftConstraint, rightConstraint, bottomContraint])
let myURL = URL(string: "")
let myRequest = URLRequest(url: myURL!)
webView.load(myRequest)
添加所需的 url,您就完成了。
关于ios - WKWebView ScaleToFit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35568868/
我对 ScaletoFit 方法有疑问。我有一个带有 UIImagesView 的 UIPageViewController,想在其中显示不同的图片,但它无法正常工作。 用这两行我初始化了图片。 se
从 UIWebView 移动到 WKWebView,我不知道如何使用 WKWebView 大小上的 loadHTMLString 函数来制作我正在加载的 HTML 以适应 View 边界。我现在加载了
在 uiimage 中缩放图像时有什么方法可以禁用抗锯齿功能吗?谢谢 最佳答案 将 QuartzCore 框架添加到您的项目中,然后将 ImageView 的 layer 的 magnificatio
我是一名优秀的程序员,十分优秀!