Last active
August 30, 2020 00:49
-
-
Save laevandus/918d37acc854e2056247bac0e75455d0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
import UIKit | |
final class BackgroundView: UIView { | |
override init(frame: CGRect) { | |
super.init(frame: .zero) | |
backgroundColor = .systemBackground | |
layer.cornerRadius = 32 | |
layer.borderColor = UIColor.systemBlue.cgColor | |
layer.borderWidth = 14 | |
} | |
required init?(coder: NSCoder) { | |
fatalError("init(coder:) has not been implemented") | |
} | |
} | |
// MARK: SwiftUI Preview | |
#if DEBUG | |
struct BackgroundViewContainer: UIViewRepresentable { | |
typealias UIViewType = BackgroundView | |
func makeUIView(context: Context) -> UIViewType { | |
return BackgroundView(frame: .zero) | |
} | |
func updateUIView(_ uiView: BackgroundView, context: Context) {} | |
} | |
struct BackgroundViewContainer_Previews: PreviewProvider { | |
static var previews: some View { | |
Group { | |
BackgroundViewContainer().colorScheme(.light) | |
BackgroundViewContainer().colorScheme(.dark) | |
}.previewLayout(.fixed(width: 200, height: 200)) | |
} | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment