help@rskworld.in +91 93305 39277
RSK World
  • Home
  • Development
    • Web Development
    • Mobile Apps
    • Software
    • Games
    • Project
  • Technologies
    • Data Science
    • AI Development
    • Cloud Development
    • Blockchain
    • Cyber Security
    • Dev Tools
    • Testing Tools
  • About
  • Contact

Theme Settings

Color Scheme
Display Options
Font Size
100%
Back to Project
RSK World
swift-ios-calculator
RSK World
swift-ios-calculator
Swift iOS Calculator v1.0 - AI Math Solver + 3D Graphing + Apple Watch Integration + iOS Widgets + Siri Shortcuts + Currency Converter + Scientific Calculator + Matrix Operations + Platform Integration + Modern iOS Development
swift-ios-calculator
  • Assets.xcassets
  • Base.lproj
  • swift-ios-calculator.xcodeproj
  • AIMathSolverViewController.swift26.6 KB
  • AppDelegate.swift1.7 KB
  • CalculatorHistoryViewController.swift6.5 KB
  • CalculatorLogic.swift4.4 KB
  • CalculatorSettingsViewController.swift5.6 KB
  • CalculatorTheme.swift8.3 KB
  • CalculatorUtils.swift6.9 KB
  • CalculatorViewController.swift3.4 KB
  • CalculatorWidget.swift14.3 KB
  • CalculatorWidgetInfo.plist846 B
  • ChemistryCalculatorViewController.swift26.9 KB
  • CurrencyConverterViewController.swift13.3 KB
  • CustomFormulaBuilderViewController.swift22.1 KB
  • EngineeringCalculatorViewController.swift25.7 KB
  • EquationSolverViewController.swift22.8 KB
  • FinancialCalculatorViewController.swift27.5 KB
  • GeometryCalculatorViewController.swift29.7 KB
  • Graphing3DViewController.swift20.8 KB
  • GraphingCalculatorViewController.swift14.7 KB
  • Info.plist3.2 KB
  • LICENSE1.1 KB
  • MainTabBarController.swift22.3 KB
  • MatrixCalculatorViewController.swift26.6 KB
  • PRIVACY_POLICY.md1.6 KB
  • PhysicsCalculatorService.swift8.2 KB
  • ProgrammerCalculatorViewController.swift11 KB
  • README.md8.7 KB
  • RELEASE_NOTES.md6.5 KB
  • SceneDelegate.swift2.8 KB
  • ScientificCalculatorViewController.swift6.2 KB
  • SiriShortcutsManager.swift23.5 KB
  • Swift iOS Calculator.entitlements1.1 KB
  • UnitConverterViewController.swift14 KB
  • WatchCalculatorViewController.swift15.3 KB
  • index.html47.5 KB
CalculatorTheme.swift
CalculatorTheme.swift
Raw Download
Find: Go to:
//
//  CalculatorTheme.swift
//  Swift iOS Calculator
//
//  Created by RSK World on 23/01/2026.
//  Copyright © 2026 RSK World. All rights reserved.
//
//  Developer: Molla Samser (Founder, RSK World)
//  Designer & Tester: Rima Khatun
//  Contact: info@rskworld.com, +91 93305 39277
//  Website: https://rskworld.in
//  Address: Nutanhat, Mongolkote, Purba Burdwan, West Bengal, India - 713147
//

import UIKit

class CalculatorTheme {
    
    // MARK: - Shared Instance
    static let shared = CalculatorTheme.lightTheme()
    
    // MARK: - Theme Properties
    var backgroundColor: UIColor
    var displayTextColor: UIColor
    var buttonBackgroundColor: UIColor
    var buttonTextColor: UIColor
    var operationButtonColor: UIColor
    var functionButtonColor: UIColor
    var accentColor: UIColor
    var textColor: UIColor
    var displayBackgroundColor: UIColor
    var name: String
    
    // MARK: - Private Initializer
    private init() {
        self.backgroundColor = .systemBackground
        self.displayTextColor = .label
        self.buttonBackgroundColor = .systemGray5
        self.buttonTextColor = .label
        self.operationButtonColor = .systemOrange
        self.functionButtonColor = .systemGray4
        self.accentColor = .systemOrange
        self.textColor = .label
        self.displayBackgroundColor = .systemGray6
        self.name = "Light"
    }
    
    // MARK: - Predefined Themes
    static func lightTheme() -> CalculatorTheme {
        let theme = CalculatorTheme()
        theme.backgroundColor = .systemBackground
        theme.displayTextColor = .label
        theme.buttonBackgroundColor = .systemGray5
        theme.buttonTextColor = .label
        theme.operationButtonColor = .systemOrange
        theme.functionButtonColor = .systemGray4
        theme.accentColor = .systemOrange
        theme.textColor = .label
        theme.displayBackgroundColor = .systemGray6
        theme.name = "Light"
        return theme
    }
    
    static func darkTheme() -> CalculatorTheme {
        let theme = CalculatorTheme()
        theme.backgroundColor = .systemBackground
        theme.displayTextColor = .label
        theme.buttonBackgroundColor = .systemGray5
        theme.buttonTextColor = .label
        theme.operationButtonColor = .systemOrange
        theme.functionButtonColor = .systemGray4
        theme.accentColor = .systemOrange
        theme.textColor = .label
        theme.displayBackgroundColor = .systemGray6
        theme.name = "Dark"
        return theme
    }
    
    static func blueTheme() -> CalculatorTheme {
        let theme = CalculatorTheme()
        theme.backgroundColor = .systemBlue
        theme.displayTextColor = .white
        theme.buttonBackgroundColor = .systemGray6
        theme.buttonTextColor = .white
        theme.operationButtonColor = .systemTeal
        theme.functionButtonColor = .systemGray5
        theme.accentColor = .systemTeal
        theme.textColor = .white
        theme.displayBackgroundColor = .systemGray5
        theme.name = "Blue"
        return theme
    }
    
    static func greenTheme() -> CalculatorTheme {
        let theme = CalculatorTheme()
        theme.backgroundColor = .systemGreen
        theme.displayTextColor = .white
        theme.buttonBackgroundColor = .systemGray6
        theme.buttonTextColor = .white
        theme.operationButtonColor = .systemYellow
        theme.functionButtonColor = .systemGray5
        theme.accentColor = .systemYellow
        theme.textColor = .white
        theme.displayBackgroundColor = .systemGray5
        theme.name = "Green"
        return theme
    }
    
    static func purpleTheme() -> CalculatorTheme {
        let theme = CalculatorTheme()
        theme.backgroundColor = .systemPurple
        theme.displayTextColor = .white
        theme.buttonBackgroundColor = .systemGray6
        theme.buttonTextColor = .white
        theme.operationButtonColor = .systemPink
        theme.functionButtonColor = .systemGray5
        theme.accentColor = .systemPink
        theme.textColor = .white
        theme.displayBackgroundColor = .systemGray5
        theme.name = "Purple"
        return theme
    }
    
    static func sunsetTheme() -> CalculatorTheme {
        let theme = CalculatorTheme()
        theme.backgroundColor = .systemOrange
        theme.displayTextColor = .white
        theme.buttonBackgroundColor = .systemGray6
        theme.buttonTextColor = .white
        theme.operationButtonColor = .systemRed
        theme.functionButtonColor = .systemGray5
        theme.accentColor = .systemRed
        theme.textColor = .white
        theme.displayBackgroundColor = .systemGray5
        theme.name = "Sunset"
        return theme
    }
    
    // MARK: - Theme Collection
    static let allThemes: [String] = ["Light", "Dark", "Blue", "Green", "Purple", "Sunset"]
    
    // MARK: - Theme Management
    static func getTheme(named name: String) -> CalculatorTheme? {
        switch name {
        case "Light": return lightTheme()
        case "Dark": return darkTheme()
        case "Blue": return blueTheme()
        case "Green": return greenTheme()
        case "Purple": return purpleTheme()
        case "Sunset": return sunsetTheme()
        default: return lightTheme()
        }
    }
    
    static func saveTheme(_ themeName: String) {
        UserDefaults.standard.set(themeName, forKey: "CalculatorTheme")
    }
    
    static func loadSavedTheme() -> CalculatorTheme {
        let themeName = UserDefaults.standard.string(forKey: "CalculatorTheme") ?? "Light"
        return getTheme(named: themeName) ?? lightTheme()
    }
    
    // MARK: - Instance Methods
    func setTheme(_ themeName: String) {
        if let newTheme = CalculatorTheme.getTheme(named: themeName) {
            backgroundColor = newTheme.backgroundColor
            displayTextColor = newTheme.displayTextColor
            buttonBackgroundColor = newTheme.buttonBackgroundColor
            buttonTextColor = newTheme.buttonTextColor
            operationButtonColor = newTheme.operationButtonColor
            functionButtonColor = newTheme.functionButtonColor
            accentColor = newTheme.accentColor
            textColor = newTheme.textColor
            displayBackgroundColor = newTheme.displayBackgroundColor
            name = newTheme.name
            CalculatorTheme.saveTheme(themeName)
        }
    }
}

// MARK: - Theme Extension for Easy Application
extension UIViewController {
    
    func applyTheme(_ theme: CalculatorTheme) {
        view.backgroundColor = theme.backgroundColor
        
        // Apply theme to all buttons in the view hierarchy
        applyThemeToSubviews(view, theme: theme)
    }
    
    private func applyThemeToSubviews(_ view: UIView, theme: CalculatorTheme) {
        for subview in view.subviews {
            if let button = subview as? UIButton {
                applyThemeToButton(button, theme: theme)
            } else if let label = subview as? UILabel {
                applyThemeToLabel(label, theme: theme)
            } else {
                applyThemeToSubviews(subview, theme: theme)
            }
        }
    }
    
    private func applyThemeToButton(_ button: UIButton, theme: CalculatorTheme) {
        // Determine button type based on title or tag
        if let title = button.currentTitle {
            switch title {
            case "+", "-", "×", "÷", "=":
                button.backgroundColor = theme.operationButtonColor
                button.setTitleColor(theme.buttonTextColor, for: .normal)
            case "AC", "+/-", "%":
                button.backgroundColor = theme.functionButtonColor
                button.setTitleColor(theme.buttonTextColor, for: .normal)
            default:
                button.backgroundColor = theme.buttonBackgroundColor
                button.setTitleColor(theme.buttonTextColor, for: .normal)
            }
        }
        
        button.layer.cornerRadius = button.frame.width / 2
        button.titleLabel?.font = UIFont.systemFont(ofSize: 24, weight: .medium)
    }
    
    private func applyThemeToLabel(_ label: UILabel, theme: CalculatorTheme) {
        if label.tag == 999 { // Display label tag
            label.textColor = theme.displayTextColor
        }
    }
}
230 lines•8.3 KB
swift

About RSK World

Founded by Molla Samser, with Designer & Tester Rima Khatun, RSK World is your one-stop destination for free programming resources, source code, and development tools.

Founder: Molla Samser
Designer & Tester: Rima Khatun

Development

  • Game Development
  • Web Development
  • Mobile Development
  • AI Development
  • Development Tools

Legal

  • Terms & Conditions
  • Privacy Policy
  • Disclaimer

Contact Info

Nutanhat, Mongolkote
Purba Burdwan, West Bengal
India, 713147

+91 93305 39277

hello@rskworld.in
support@rskworld.in

© 2026 RSK World. All rights reserved.

Content used for educational purposes only. View Disclaimer