Skip to content

Instantly share code, notes, and snippets.

@Koze
Last active March 5, 2020 19:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Koze/d7ad0b172794fd3b55fb76ebc6f03051 to your computer and use it in GitHub Desktop.
Save Koze/d7ad0b172794fd3b55fb76ebc6f03051 to your computer and use it in GitHub Desktop.
Using SwiftUI preview with UIView
//
// TableViewCellPreview.swift
// iOS12App
//
// Created by Kazuma Koze on 2020/03/05.
// Copyright © 2020 Climb App. All rights reserved.
//
import SwiftUI
@available(iOS 13.0, *)
struct TableViewCellPreview: PreviewProvider, UIViewRepresentable {
static var previews: some View {
Group {
TableViewCellPreview()
.environment(\.sizeCategory, .medium)
.previewLayout(.sizeThatFits)
TableViewCellPreview()
.environment(\.sizeCategory, .accessibilityExtraExtraExtraLarge)
.previewLayout(.sizeThatFits)
}
}
func makeUIView(context: UIViewRepresentableContext<TableViewCellPreview>) -> TableViewCell {
let nib = UINib(nibName: String(describing: TableViewCell.self), bundle: nil)
let cell = nib.instantiate(withOwner: nil, options: nil).first as! TableViewCell
return cell
}
func updateUIView(_ uiView: TableViewCell, context: UIViewRepresentableContext<TableViewCellPreview>) {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment