如何在webview中修复调整视频HTML的大小?

时间:2017-03-14 13:40:06

标签: html ios swift xcode webview

如何使用HTML代码在webview中修复此视频,我使用WordPress应用

import UIKit

class ShowAricleVCViewController: UIViewController {

    @IBOutlet weak var webview: UIWebView!

    var Content : String!



    override func viewDidLoad() {


    }


    override func viewWillAppear(_ animated: Bool) {

        let TheHtmlAfter = HTMLImageCorrector(HTMLString: Content)

            webview.loadHTMLString(TheHtmlAfter, baseURL: nil)

    }



    func HTMLImageCorrector(HTMLString: String) -> String {
        let htmlString: String = "<html> <meta name='viewport' content='width=device-width, initial-scale=1'><head><style>body { background: white } p { color: #555555; font-family: 'Avenir-Book'; font-size: 14px } img { border-radius: 8px; max-width: 100%; max-height: 220px; display: block; margin-left: auto; margin-right: auto;} </style></head><body><img align=\"middle\" > <p>\(HTMLString)<p></body></html>"
        return htmlString
    }

这段代码只是修复了图片和字体以及背景 我需要修复视频scle

   func HTMLImageCorrector(HTMLString: String) -> String {
        let htmlString: String = "<html> <meta name='viewport' content='width=device-width, initial-scale=1'><head><style>body { background: white } p { color: #555555; font-family: 'Avenir-Book'; font-size: 14px } img { border-radius: 8px; max-width: 100%; max-height: 220px; display: block; margin-left: auto; margin-right: auto;} </style></head><body><img align=\"middle\" > <p>\(HTMLString)<p></body></html>"
        return htmlString
    }[enter image description here][1]

2 个答案:

答案 0 :(得分:1)

func HTMLImageCorrector(HTMLString: String) -> String {
        let htmlString: String = "<html> <meta name='viewport' content='width=device-width, initial-scale=1'><head><style>body { background: white } p { color: #555555; font-family: 'Avenir-Book'; font-size: 14px } img { border-radius: 8px; max-width: 100%; max-height: 220px; display: block; margin-left: auto; margin-right: auto;} iframe { border-radius: 8px; max-width: 100%; max-height: 220px; display: block; margin-left: auto; margin-right: auto;} </style></head><body><img align=\"middle\" > <p><div dir='rtl'><center>\(HTMLString)</center></div><p></body></html>"
        return htmlString
    }

答案 1 :(得分:0)

我不确定我100%理解你的问题。但是,如果您只需要以响应方式标记HTML中的视频并保持其​​宽高比,我曾经遇到过这个有用的帖子并且从那时起就一直在使用它:

Filter