TRVideoView
这是一个简单的 WKWebView,用于从 YouTube 和 Vimeo 嵌入视频。
功能
- 提供文本并返回 WKWebView
- 检查文本中是否有链接
- 返回不包含链接的字符串
- 调整 WebView 大小
要求
- iOS 9.0
- Swift 3.2
- Xcode 9
安装
CocoaPods
使用 CocoaPods 将其整合到您的 Xcode 项目中,请在您的 Podfile
中添加它。
pod 'TRVideoView'
然后,运行以下命令
$ pod install
使用方法
// Initialize
let video = TRVideoView(text: "This is some sample text with a YouTube link https://www.youtube.com/watch?v=QPAloq5MCUA")
// Set the frame as always
video.frame = CGRect(x: 0, y: 0, width: 300, height: 150)
// Returns true or false (checks for YouTube and Vimeo urls)
video.containsURLs()
// Returns String with out URLs (i.e. "This is some sample text with a YouTube link")
let text = video.textWithoutURLs()
// Finally add it to your view
self.view.addSubview(video)
关于链接的说明
对于 YouTube,请使用 https://youtu.be/QPAloq5MCUA
或 https://www.youtube.com/watch?v=QPAloq5MCUA
。
对于 Vimeo,请使用 https://vimeo.com/86033976
。
如果链接中包含其他参数,没有关系,它们会被整理好。
贡献
想看到支持更多视频服务?您可以从创建一个问题开始,我会看看我能做什么。
如果您想分叉此项目并添加更多功能,请继续提交 PR,我很高兴看到您的贡献。