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
CalculatorSettingsViewController.swift
CalculatorSettingsViewController.swift
Raw Download
Find: Go to:
//
//  CalculatorSettingsViewController.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 CalculatorSettingsViewController: UIViewController {
    
    // MARK: - Outlets
    @IBOutlet weak var tableView: UITableView!
    @IBOutlet weak var themePreviewView: UIView!
    @IBOutlet weak var soundSwitch: UISwitch!
    @IBOutlet weak var hapticSwitch: UISwitch!
    @IBOutlet weak var decimalPlacesStepper: UIStepper!
    @IBOutlet weak var decimalPlacesLabel: UILabel!
    
    // MARK: - Properties
    private var selectedTheme: CalculatorTheme = CalculatorTheme.shared
    private var settings = CalculatorSettings()
    
    // MARK: - Lifecycle
    override func viewDidLoad() {
        super.viewDidLoad()
        setupUI()
        loadSettings()
    }
    
    // MARK: - UI Setup
    private func setupUI() {
        title = "Settings"
        navigationItem.rightBarButtonItem = UIBarButtonItem(
            barButtonSystemItem: .done,
            target: self,
            action: #selector(doneTapped)
        )
        
        tableView.delegate = self
        tableView.dataSource = self
        
        setupThemePreview()
        updateUI()
    }
    
    private func setupThemePreview() {
        themePreviewView.layer.cornerRadius = 12
        themePreviewView.layer.borderWidth = 1
        themePreviewView.layer.borderColor = UIColor.systemGray4.cgColor
    }
    
    private func updateUI() {
        soundSwitch.isOn = settings.soundEnabled
        hapticSwitch.isOn = settings.hapticFeedbackEnabled
        decimalPlacesStepper.value = Double(settings.decimalPlaces)
        decimalPlacesLabel.text = "\(settings.decimalPlaces) decimal places"
        
        updateThemePreview()
    }
    
    private func updateThemePreview() {
        themePreviewView.backgroundColor = selectedTheme.backgroundColor
    }
    
    private func loadSettings() {
        if let data = UserDefaults.standard.data(forKey: "CalculatorSettings"),
           let decoded = try? JSONDecoder().decode(CalculatorSettings.self, from: data) {
            settings = decoded
        }
    }
    
    private func saveSettings() {
        if let encoded = try? JSONEncoder().encode(settings) {
            UserDefaults.standard.set(encoded, forKey: "CalculatorSettings")
        }
        
        CalculatorTheme.saveTheme(selectedTheme)
    }
    
    // MARK: - Actions
    @objc private func doneTapped() {
        saveSettings()
        dismiss(animated: true)
    }
    
    @IBAction func soundSwitchChanged(_ sender: UISwitch) {
        settings.soundEnabled = sender.isOn
    }
    
    @IBAction func hapticSwitchChanged(_ sender: UISwitch) {
        settings.hapticFeedbackEnabled = sender.isOn
    }
    
    @IBAction func decimalPlacesChanged(_ sender: UIStepper) {
        settings.decimalPlaces = Int(sender.value)
        decimalPlacesLabel.text = "\(settings.decimalPlaces) decimal places"
    }
    
    @IBAction func resetSettingsTapped(_ sender: UIButton) {
        let alert = UIAlertController(
            title: "Reset Settings",
            message: "Are you sure you want to reset all settings to default?",
            preferredStyle: .alert
        )
        
        alert.addAction(UIAlertAction(title: "Cancel", style: .cancel))
        alert.addAction(UIAlertAction(title: "Reset", style: .destructive) { _ in
            self.settings = CalculatorSettings()
            self.selectedTheme = .light
            self.updateUI()
        })
        
        present(alert, animated: true)
    }
}

// MARK: - UITableViewDataSource
extension CalculatorSettingsViewController: UITableViewDataSource {
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return CalculatorTheme.allThemes.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "ThemeCell", for: indexPath)
        let theme = CalculatorTheme.allThemes[indexPath.row]
        
        cell.textLabel?.text = theme.name
        cell.backgroundColor = theme.backgroundColor
        cell.textLabel?.textColor = theme.displayTextColor
        
        if theme.name == selectedTheme.name {
            cell.accessoryType = .checkmark
        } else {
            cell.accessoryType = .none
        }
        
        return cell
    }
}

// MARK: - UITableViewDelegate
extension CalculatorSettingsViewController: UITableViewDelegate {
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        tableView.deselectRow(at: indexPath, animated: true)
        
        selectedTheme = CalculatorTheme.allThemes[indexPath.row]
        updateThemePreview()
        tableView.reloadData()
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 60
    }
}

// MARK: - Settings Model
struct CalculatorSettings: Codable {
    var soundEnabled: Bool = true
    var hapticFeedbackEnabled: Bool = true
    var decimalPlaces: Int = 8
    var scientificModeEnabled: Bool = false
    var historyEnabled: Bool = true
    var autoRotateEnabled: Bool = true
}
175 lines•5.6 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