-
Notifications
You must be signed in to change notification settings - Fork 0
/
TextEditorBootcamp.swift
71 lines (59 loc) · 2.56 KB
/
TextEditorBootcamp.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
65
66
67
68
69
70
71
//
// TextEditorBootcamp.swift
// SwiftfulThinkingBootcamp
//
// Created by enesozmus on 11.05.2024.
//
import SwiftUI
struct TextEditorBootcamp: View {
@State var textEditorText: String = "This is the starting text."
@State var savedText: String = ""
var body: some View {
NavigationStack {
VStack {
TextEditor(text: $textEditorText)
.frame(height: 250)
.foregroundStyle(.black.opacity(0.8))
// 🟩 We cannot change the background color of 'TextEditor' directly, first we have to hide the default background using this code, then apply background.
.scrollContentBackground(.hidden)
.background(.yellow.opacity(0.45)) // To see this
.clipShape(.rect(cornerRadii: .init(topLeading: 10, bottomLeading: 10, bottomTrailing: 10, topTrailing: 10)))
//.colorMultiply(Color(#colorLiteral(red: 0.8374180198, green: 0.8374378085, blue: 0.8374271393, alpha: 1)))
Button(action: {
savedText = textEditorText
}, label: {
Text("Save".uppercased())
.font(.headline)
.foregroundColor(.white)
.padding()
.frame(maxWidth: .infinity)
.background(Color.blue)
.clipShape(.rect(cornerRadii: .init(topLeading: 10, bottomLeading: 10, bottomTrailing: 10, topTrailing: 10)))
})
Text(savedText)
Spacer()
}
.padding()
.navigationTitle("TextEditor Bootcamp!")
}
}
}
#Preview {
TextEditorBootcamp()
}
/*
🔴 TextEditor
→ A view that can display and edit long-form text.
→ A text editor view allows you to display and edit multiline, scrollable text in your app’s user interface.
@State private var fullText: String = "This is some editable text..."
TextEditor(text: $fullText)
.foregroundColor(Color.gray)
.font(.custom("HelveticaNeue", size: 13))
.lineSpacing(5)
TextEditor(text: $textEditorText)
.padding([.leading, .trailing], 1)
.overlay(
RoundedRectangle(cornerRadius: 10)
.stroke(Color(.systemGray5), lineWidth: 2.0)
)
*/