SwiftUI: Difference between revisions
Jump to navigation
Jump to search
Line 154: | Line 154: | ||
* [https://stackoverflow.com/questions/54971163 Set environment variable <code>CG_PDF_VERBOSE</code>] | * [https://stackoverflow.com/questions/54971163 Set environment variable <code>CG_PDF_VERBOSE</code>] | ||
* [https://stackoverflow.com/questions/748175 Asynchronous vs Synchronous] | * [https://stackoverflow.com/questions/748175 Asynchronous vs Synchronous] | ||
* [https://www.hackingwithswift.com/books/ios-swiftui/working-with-identifiable-items-in-swiftui Identifiable items in SwiftUI] | |||
* [https://github.com/Dalodd/Alamofire-Synchronous Alamofire Synchronous] | * [https://github.com/Dalodd/Alamofire-Synchronous Alamofire Synchronous] | ||
* [https://stackoverflow.com/questions/30930223 Adjust alpha of UIColor] | * [https://stackoverflow.com/questions/30930223 Adjust alpha of UIColor] | ||
|} | |} |
Revision as of 09:37, 20 April 2020
ContentView
import SwiftUI
struct ContentView: View {
var body: some View {
VStack(alignment: .leading) {
Text("Turtle Rock")
.font(.title)
HStack {
Text("Joshua Tree National Park")
.font(.subheadline)
Spacer()
Text("California")
.font(.subheadline)
}
}
.padding()
}
}
struct ContentView_Preview: PreviewProvider {
static var previews: some View {
ContentView()
}
}
MyPDFView
// MARK: - MyPDFView
fileprivate struct MyPDFView: UIViewRepresentable {
@Binding var data: Data
func makeUIView(context: UIViewRepresentableContext<MyPDFView>) -> UIView {
let empty = UIView()
//guard let provider = CGDataProvider(data: self.data as CFData) else {return empty}
//guard let document = CGPDFDocument(provider) else {return empty}
guard let url = URL(string: "https://api.chorke.org/academia/api/v1.0/health/card/01890600.pdf") else {return empty}
guard let document = CGPDFDocument(url as CFURL) else {return empty}
guard let page = document.page(at: 1) else {return empty}
let pageRect = page.getBoxRect(.mediaBox)
let renderer = UIGraphicsImageRenderer(size: pageRect.size)
let uiImage = renderer.image { ctx in
UIColor.white.set()
ctx.fill(pageRect)
ctx.cgContext.translateBy(x: 0.0, y: pageRect.size.height)
ctx.cgContext.scaleBy(x: 1.0, y: -1.0)
ctx.cgContext.drawPDFPage(page)
}
let view = UIImageView(image: uiImage)
view.contentMode = .scaleAspectFill
return view
}
func updateUIView(_ view: UIView, context: UIViewRepresentableContext<MyPDFView>) {
// MARK: - TODO
}
}