comparison Simoleon/Helpers/CurrencyRow.swift @ 13:cdc5f728b105

Minor UI updates
author Dennis Concepción Martín <dennisconcepcionmartin@gmail.com>
date Tue, 13 Jul 2021 19:56:33 +0100
parents a62e5e4a4f02
children 03ce7421c6f4
comparison
equal deleted inserted replaced
12:81f4e0a3b1eb 13:cdc5f728b105
35 } 35 }
36 .padding(.horizontal) 36 .padding(.horizontal)
37 37
38 VStack(alignment: .leading) { 38 VStack(alignment: .leading) {
39 Text("Bid") 39 Text("Bid")
40 Text("\(currencyQuote.bid!, specifier: "%.4f")") 40 let bid = currencyQuote.bid!
41 Text("\(bid, specifier: createSpecifier(bid))")
41 .fontWeight(.semibold) 42 .fontWeight(.semibold)
43 .lineLimit(1)
42 44
43 } 45 }
44 .padding(.trailing) 46 .padding(.trailing)
45 47
46 VStack(alignment: .leading) { 48 VStack(alignment: .leading) {
47 Text("Ask") 49 Text("Ask")
48 Text("\(currencyQuote.ask!, specifier: "%.4f")") 50 let ask = currencyQuote.ask!
51 Text("\(ask, specifier: createSpecifier(ask))")
49 .fontWeight(.semibold) 52 .fontWeight(.semibold)
53 .lineLimit(1)
50 54
51 } 55 }
52 56
53 Spacer() 57 Spacer()
54 } 58 }
57 .offset(x: -10.0, y: -120.0) 61 .offset(x: -10.0, y: -120.0)
58 .padding(.bottom, -120) 62 .padding(.bottom, -120)
59 } 63 }
60 .padding(.leading, 10) 64 .padding(.leading, 10)
61 .padding(.horizontal) 65 .padding(.horizontal)
66 }
67
68 /*
69 Choose how many decimals depending on whether the price is hundreds, thousands, etc
70 */
71
72 private func createSpecifier(_ amount: Float) -> String {
73 if amount >= 10 {
74 return "%.2f"
75 } else {
76 return "%.4f"
77 }
62 } 78 }
63 } 79 }
64 extension RoundedRectangle { 80 extension RoundedRectangle {
65 func rectangleModifier(_ colour: Color, _ height: CGFloat) -> some View { 81 func rectangleModifier(_ colour: Color, _ height: CGFloat) -> some View {
66 self 82 self