-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathContentView.swift
55 lines (48 loc) · 1.47 KB
/
ContentView.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
//
// ContentView.swift
// CelciusFahrenheitConverter
//
// Created by Mustafa Murat Arat on 8/11/23.
//
import SwiftUI
struct ContentView: View{
@State private var celcius: Double = 0.0
@State private var fahrenheit: Double = 0.0
var body: some View{
VStack{
Spacer()
Image("logo")
.resizable()
.scaledToFit()
.frame(width: 150, height: 150, alignment: .bottom)
Text("Celcius to Fahrenheit Converter")
.font(.system(size: 23))
.fontWeight(.bold)
TextField("Enter Celcius", value: $celcius, formatter: NumberFormatter())
.textFieldStyle(RoundedBorderTextFieldStyle())
.padding()
.keyboardType(.decimalPad)
Text("Fahrenheit: \(String(format: "%.2f", fahrenheit))")
.font(.title)
.padding()
Button("Convert", action:{
convertToCelcius()
})
.buttonStyle(.borderedProminent)
.controlSize(.large)
.buttonBorderShape(.capsule)
.tint(.black)
.font(.system(size: 15))
Spacer()
}
.padding()
}
private func convertToCelcius() {
fahrenheit = (celcius * 9/5) + 32.0
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}