forked from pencilresearch/OpenScanner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathViewExtensions.swift
62 lines (51 loc) · 1.37 KB
/
ViewExtensions.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//
// ViewExtensions.swift
// scanner
//
// Created by Slaven Radic on 2022-07-25.
//
import Foundation
import SwiftUI
public extension Color {
static let background = Color("background")
static let foreground = Color("foreground")
static let accent = Color("accent")
init(hex: UInt, alpha: Double = 1) {
self.init(
.sRGB,
red: Double((hex >> 16) & 0xff) / 255,
green: Double((hex >> 08) & 0xff) / 255,
blue: Double((hex >> 00) & 0xff) / 255,
opacity: alpha
)
}
}
struct SmallThumbnail: View {
var image: UIImage?
var size: CGSize = CGSize(width: 80, height: 80)
var body: some View {
ZStack {
if image != nil {
Image(uiImage: image ?? UIImage())
.resizable()
.aspectRatio(1.0, contentMode: .fit)
.clipShape(RoundedRectangle(cornerRadius: 8))
} else {
Image(systemName: "viewfinder")
.font(.system(size: size.width * 0.5, weight: .ultraLight))
}
RoundedRectangle(cornerRadius: 8)
.stroke(Color.background, lineWidth: 2)
}
.foregroundColor(Color.primary)
.frame(width: size.width, height: size.height)
}
}
func getDocumentsDirectory() -> URL {
let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
return paths[0]
}
func getTemporaryDirectory() -> URL {
let previewURL = FileManager.default.temporaryDirectory.appendingPathComponent("Document")
return previewURL
}