
一、 開發前準備
- 環境: Xcode 15+ / Swift 5.9+框架: * SwiftUI: 建構使用者介面。Swift Charts: 製作圖片中的複利增長曲線。Combine 或 Swift Data: 處理數據流與本地存儲。
二、 核心功能開發步驟
1. 建立複利數據模型 (Data Model)
首先,我們需要一個邏輯來計算投資增長。複利公式如下:$$A = P(1 + r)^n$$
在 Swift 中,我們可以建立一個簡單的函式:
Swiftstruct GrowthData: Identifiable { let id = UUID() let month: Int let balance: Double } func calculateCompoundInterest(principal: Double, monthlyContribution: Double, annualRate: Double, months: Int) -> [GrowthData] { var data: [GrowthData] = [] var currentBalance = principal let monthlyRate = annualRate / 12 for i in 1...months { currentBalance = (currentBalance + monthlyContribution) * (1 + monthlyRate) data.append(GrowthData(month: i, balance: currentBalance)) } return data }
2. 製作增長曲線圖表 (Swift Charts)
使用 Chart 視圖來呈現圖片中上方的橘色曲線。
Swiftimport SwiftUI import Charts struct InvestmentChartView: View { let data: [GrowthData] var body: some View { Chart(data) { point in LineMark( x: .value("月份", point.month), y: .value("金額", point.balance) ) .interpolationMethod(.catmullRom) // 讓線條圓滑 .foregroundStyle(.orange) AreaMark( x: .value("月份", point.month), y: .value("金額", point.balance) ) .foregroundStyle(LinearGradient(colors: [.orange.opacity(0.3), .clear], startPoint: .top, endPoint: .bottom)) } .frame(height: 250) } }
3. 設計 ETF 資訊卡片 (Grid Layout)
圖片下方顯示了 0050, 00878 等資訊,我們可以使用 LazyVGrid 來排列。
Swiftstruct ETFCard: View { let code: String let change: Double var body: some View { VStack(alignment: .leading, spacing: 8) { Text(code) .font(.headline) HStack { Image(systemName: "triangle.fill") Text("\(change, specifier: "%.1f")%") } .font(.caption) .foregroundColor(.green) } .padding() .background(Color.secondary.opacity(0.1)) .cornerRadius(12) } }
三、 UI 優化重點(仿照圖片風格)
- 深色模式 (Dark Mode): 圖片顯示為深色主題,建議在 Assets.xcassets 中設定對應的顏色。磨砂玻璃效果: 資訊板塊可以使用 .background(.ultraThinMaterial)。金幣與圖形裝飾: 雖然這是視覺裝飾,但在 UI 研發上,可以使用 ZStack 配合 Image(systemName:) 的轉譯來增強動感。
四、 如何「賺錢」?(商業化建議)
教學標題提到「賺錢教學」,針對這類工具 App,有幾種常見的變現方式:
- 訂閱制 (SaaS): 鎖定「進階回測功能」或「即時股價 API」,每月收取訂閱費。廣告介接: 雖然圖片很乾淨,但底部可放置細微的 Banner 廣告。導流聯盟行銷: 在 App 中加入「開戶券商推薦」連結,獲取佣金。
總結
開發這款 App 的核心在於 「數據的可視化」。建議先從手動輸入預期報酬率開始,再進階到串連金融 API (如 Yahoo Finance API) 來獲取即時的 ETF 價格。
























