mirror of
https://github.com/ivanvorobei/SwiftUI.git
synced 2026-05-28 10:29:28 +02:00
Add Async image loading
This commit is contained in:
+47
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
See LICENSE folder for this sample’s licensing information.
|
||||
|
||||
Abstract:
|
||||
A view wrapping a UIPageControl.
|
||||
*/
|
||||
|
||||
import SwiftUI
|
||||
|
||||
import UIKit
|
||||
|
||||
struct PageControl: UIViewRepresentable {
|
||||
var numberOfPages: Int
|
||||
@Binding var currentPage: Int
|
||||
|
||||
func makeCoordinator() -> Coordinator {
|
||||
Coordinator(self)
|
||||
}
|
||||
|
||||
func makeUIView(context: Context) -> UIPageControl {
|
||||
let control = UIPageControl()
|
||||
control.numberOfPages = numberOfPages
|
||||
control.addTarget(
|
||||
context.coordinator,
|
||||
action: #selector(Coordinator.updateCurrentPage(sender:)),
|
||||
for: .valueChanged)
|
||||
|
||||
return control
|
||||
}
|
||||
|
||||
func updateUIView(_ uiView: UIPageControl, context: Context) {
|
||||
uiView.currentPage = currentPage
|
||||
}
|
||||
|
||||
class Coordinator: NSObject {
|
||||
var control: PageControl
|
||||
|
||||
init(_ control: PageControl) {
|
||||
self.control = control
|
||||
}
|
||||
|
||||
@objc
|
||||
func updateCurrentPage(sender: UIPageControl) {
|
||||
control.currentPage = sender.currentPage
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user