Mercurial > public > lazybear
changeset 115:33e03e2863f6
Implementing TabView
author | Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com> |
---|---|
date | Thu, 04 Feb 2021 20:36:33 +0100 |
parents | 4c172ff9af20 |
children | 4e920489a57e |
files | LazyBear.xcodeproj/project.xcworkspace/xcuserdata/dennis.xcuserdatad/UserInterfaceState.xcuserstate lazybear/Views/Company.swift lazybear/Views/Price.swift |
diffstat | 3 files changed, 39 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
Binary file LazyBear.xcodeproj/project.xcworkspace/xcuserdata/dennis.xcuserdatad/UserInterfaceState.xcuserstate has changed
--- a/lazybear/Views/Company.swift Thu Feb 04 20:07:29 2021 +0100 +++ b/lazybear/Views/Company.swift Thu Feb 04 20:36:33 2021 +0100 @@ -13,17 +13,38 @@ let persistenceController = PersistenceController.shared + var views = ["Stock", "Insiders"] + @State private var selectedView = 0 + var body: some View { - CompanyHeader(name: self.name, symbol: self.symbol) - GeometryReader { geo in - ScrollView { - VStack(alignment: .leading) { - Stock(name: name, symbol: symbol, lineChartHeight: geo.size.height*0.2) - .padding(.bottom) - + VStack { + CompanyHeader(name: self.name, symbol: self.symbol) + TabView { + // First view + GeometryReader { geo in + ScrollView { + VStack(alignment: .leading) { + Stock(name: name, symbol: symbol, lineChartHeight: geo.size.height*0.2) + .padding(.bottom) + + + } + .environment(\.managedObjectContext, persistenceController.container.viewContext) + } + } + .tabItem { + Image(systemName: "1.circle") + Text("First") + }.tag(0) + + // Second view + ScrollView { InsiderTransactions(symbol: symbol) } - .environment(\.managedObjectContext, persistenceController.container.viewContext) + .tabItem { + Image(systemName: "2.circle") + Text("Second") + }.tag(1) } } }
--- a/lazybear/Views/Price.swift Thu Feb 04 20:07:29 2021 +0100 +++ b/lazybear/Views/Price.swift Thu Feb 04 20:36:33 2021 +0100 @@ -32,7 +32,7 @@ Text("\(data[0].changePercent ?? 0 * 100, specifier: "%.2f")%") .font(.subheadline) .foregroundColor(.white) - //.background(Color(negativeChange ? .red : .green).cornerRadius(5)) + .background(percentageColor().cornerRadius(5)) } .if(showVertical) { content in HStack { content } @@ -59,6 +59,15 @@ self.data = [QuoteModel(latestPrice: result.latestPrice, changePercent: result.changePercent)] } } + + private func percentageColor() -> Color { + var color: Color = .red + if data[0].changePercent ?? 0 >= 0 { + color = .green + } + + return color + } } // Wrap content if some condition is satisfied extension View {