TTBaseWKWebView
DisplayA WKWebView subclass with built-in GIF support (no scroll, tap handler), skeleton loading overlay, and two HTML string extension helpers that inject a responsive viewport meta tag automatically.
🚀 Usage
// GIF viewer (non-scrollable, tappable)
let gifView = TTBaseWKWebView(gifNameString: "loading_animation")
gifView.onTouchHandler = { [weak self] _ in
self?.dismiss(animated: true)
}
view.addSubview(gifView)
gifView.setFullContraints(constant: 0)
// Skeleton loading overlay
gifView.onAddSkeletonMark() // Show skeleton
gifView.onRemoveSkeletonMark() // Fade out and remove
// Load HTML with responsive viewport
webView.loadHTMLStringWithMagic(
content: articleHTML,
baseURL: nil
)
// Load HTML with Apple-system font styling
webView.loadHTMLStringWithMagicByAppleStyle(
content: richTextHTML,
color: .label,
size: 16,
font: "-apple-system"
)
📖 API Reference
| Member | Type | Description |
|---|---|---|
init(gifNameString:) | Init | Load .gif from bundle; non-scrollable, tap-enabled |
onTouchHandler | (TTBaseWKWebView) → Void | Tap callback |
onAddSkeletonMark() | Method | Overlay skeleton placeholder (safe: checks tag) |
onRemoveSkeletonMark() | Method | Fade out and remove skeleton |
loadHTMLStringWithMagic(content:baseURL:) | Extension | Load HTML with mobile viewport meta |
loadHTMLStringWithMagicByAppleStyle(…) | Extension | Load HTML with font/color/size styling injected |
Pro Tip: Use
loadHTMLStringWithMagicByAppleStyle for rich text content (blog posts, notifications) — it injects -apple-system font and .label color matching the user's current appearance mode. Pass color.hexString if you have it.