TTBaseWKWebView

Display

A 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

MemberTypeDescription
init(gifNameString:)InitLoad .gif from bundle; non-scrollable, tap-enabled
onTouchHandler(TTBaseWKWebView) → VoidTap callback
onAddSkeletonMark()MethodOverlay skeleton placeholder (safe: checks tag)
onRemoveSkeletonMark()MethodFade out and remove skeleton
loadHTMLStringWithMagic(content:baseURL:)ExtensionLoad HTML with mobile viewport meta
loadHTMLStringWithMagicByAppleStyle(…)ExtensionLoad 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.