-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathScaledMisticaButton.swift
64 lines (59 loc) · 1.87 KB
/
ScaledMisticaButton.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
63
64
//
// ScaledMisticaButton.swift
//
// Made with ❤️ by Novum
//
// Copyright © Telefonica. All rights reserved.
//
import SwiftUI
struct ScaledMisticaButton<Content: View>: View {
let content: () -> Content
let height: CGFloat
let small: Bool
let minWidth: CGFloat
let verticalPadding: CGFloat
let horizontalPadding: CGFloat
let backgroundColor: Color
let foregroundColor: Color
let borderColor: Color
let leadingInset: CGFloat
let trailingInset: CGFloat
@ScaledMetric var scale: CGFloat = 1
init(
height: CGFloat,
small: Bool,
minWidth: CGFloat,
verticalPadding: CGFloat,
horizontalPadding: CGFloat,
backgroundColor: Color,
foregroundColor: Color,
borderColor: Color,
leadingInset: CGFloat,
trailingInset: CGFloat,
@ViewBuilder content: @escaping () -> Content
) {
self.height = height
self.small = small
self.minWidth = minWidth
self.content = content
self.verticalPadding = verticalPadding
self.horizontalPadding = horizontalPadding
self.backgroundColor = backgroundColor
self.foregroundColor = foregroundColor
self.borderColor = borderColor
self.leadingInset = leadingInset
self.trailingInset = trailingInset
}
var body: some View {
content()
.frame(height: height * scale)
.if(!small) { $0.expandHorizontally() }
.frame(minWidth: minWidth * scale)
.padding(.vertical, verticalPadding)
.padding(.horizontal, horizontalPadding)
.background(backgroundColor)
.foregroundColor(foregroundColor)
.border(radiusStyle: .button, borderColor: borderColor)
.padding(EdgeInsets(top: 0, leading: leadingInset, bottom: 0, trailing: trailingInset))
}
}