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.swiftSiriShortcutsManager.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
SiriShortcutsManager.swift
Raw Download
Find: Go to:
//
//  SiriShortcutsManager.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
import Intents
import IntentsUI

class SiriShortcutsManager {
    
    static let shared = SiriShortcutsManager()
    
    private init() {}
    
    // MARK: - Shortcut Types
    enum ShortcutType: String, CaseIterable {
        case calculate = "com.rskworld.calculator.calculate"
        case unitConvert = "com.rskworld.calculator.unitConvert"
        case currencyConvert = "com.rskworld.calculator.currencyConvert"
        case scientificCalculate = "com.rskworld.calculator.scientificCalculate"
        case programmerCalculate = "com.rskworld.calculator.programmerCalculate"
        case graphFunction = "com.rskworld.calculator.graphFunction"
        case tipCalculator = "com.rskworld.calculator.tipCalculator"
        case loanCalculator = "com.rskworld.calculator.loanCalculator"
        case bmiCalculator = "com.rskworld.calculator.bmiCalculator"
        case percentageCalculator = "com.rskworld.calculator.percentageCalculator"
    }
    
    // MARK: - Setup Shortcuts
    func setupAllShortcuts() {
        setupCalculateShortcut()
        setupUnitConvertShortcut()
        setupCurrencyConvertShortcut()
        setupScientificCalculateShortcut()
        setupProgrammerCalculateShortcut()
        setupGraphFunctionShortcut()
        setupTipCalculatorShortcut()
        setupLoanCalculatorShortcut()
        setupBMICalculatorShortcut()
        setupPercentageCalculatorShortcut()
    }
    
    // MARK: - Calculate Shortcut
    private func setupCalculateShortcut() {
        let activity = NSUserActivity(activityType: ShortcutType.calculate.rawValue)
        activity.title = "Quick Calculate"
        activity.suggestedInvocationPhrase = "Quick calculate"
        activity.isEligibleForPrediction = true
        activity.persistentIdentifier = ShortcutType.calculate.rawValue
        
        let userInfo: [String: Any] = [
            "action": "calculate",
            "type": "basic"
        ]
        activity.userInfo = userInfo
        
        self.viewController?.userActivity = activity
        activity.becomeCurrent()
    }
    
    // MARK: - Unit Convert Shortcut
    private func setupUnitConvertShortcut() {
        let activity = NSUserActivity(activityType: ShortcutType.unitConvert.rawValue)
        activity.title = "Convert Units"
        activity.suggestedInvocationPhrase = "Convert units"
        activity.isEligibleForPrediction = true
        activity.persistentIdentifier = ShortcutType.unitConvert.rawValue
        
        let userInfo: [String: Any] = [
            "action": "convert",
            "type": "units",
            "category": "length",
            "fromUnit": "meter",
            "toUnit": "foot"
        ]
        activity.userInfo = userInfo
        
        self.viewController?.userActivity = activity
        activity.becomeCurrent()
    }
    
    // MARK: - Currency Convert Shortcut
    private func setupCurrencyConvertShortcut() {
        let activity = NSUserActivity(activityType: ShortcutType.currencyConvert.rawValue)
        activity.title = "Convert Currency"
        activity.suggestedInvocationPhrase = "Convert currency"
        activity.isEligibleForPrediction = true
        activity.persistentIdentifier = ShortcutType.currencyConvert.rawValue
        
        let userInfo: [String: Any] = [
            "action": "convert",
            "type": "currency",
            "fromCurrency": "USD",
            "toCurrency": "EUR"
        ]
        activity.userInfo = userInfo
        
        self.viewController?.userActivity = activity
        activity.becomeCurrent()
    }
    
    // MARK: - Scientific Calculate Shortcut
    private func setupScientificCalculateShortcut() {
        let activity = NSUserActivity(activityType: ShortcutType.scientificCalculate.rawValue)
        activity.title = "Scientific Calculator"
        activity.suggestedInvocationPhrase = "Scientific calculator"
        activity.isEligibleForPrediction = true
        activity.persistentIdentifier = ShortcutType.scientificCalculate.rawValue
        
        let userInfo: [String: Any] = [
            "action": "calculate",
            "type": "scientific"
        ]
        activity.userInfo = userInfo
        
        self.viewController?.userActivity = activity
        activity.becomeCurrent()
    }
    
    // MARK: - Programmer Calculate Shortcut
    private func setupProgrammerCalculateShortcut() {
        let activity = NSUserActivity(activityType: ShortcutType.programmerCalculate.rawValue)
        activity.title = "Programmer Calculator"
        activity.suggestedInvocationPhrase = "Programmer calculator"
        activity.isEligibleForPrediction = true
        activity.persistentIdentifier = ShortcutType.programmerCalculate.rawValue
        
        let userInfo: [String: Any] = [
            "action": "calculate",
            "type": "programmer",
            "base": "decimal",
            "bitLength": "32"
        ]
        activity.userInfo = userInfo
        
        self.viewController?.userActivity = activity
        activity.becomeCurrent()
    }
    
    // MARK: - Graph Function Shortcut
    private func setupGraphFunctionShortcut() {
        let activity = NSUserActivity(activityType: ShortcutType.graphFunction.rawValue)
        activity.title = "Graph Function"
        activity.suggestedInvocationPhrase = "Graph function"
        activity.isEligibleForPrediction = true
        activity.persistentIdentifier = ShortcutType.graphFunction.rawValue
        
        let userInfo: [String: Any] = [
            "action": "graph",
            "function": "x^2",
            "xMin": -10,
            "xMax": 10
        ]
        activity.userInfo = userInfo
        
        self.viewController?.userActivity = activity
        activity.becomeCurrent()
    }
    
    // MARK: - Tip Calculator Shortcut
    private func setupTipCalculatorShortcut() {
        let activity = NSUserActivity(activityType: ShortcutType.tipCalculator.rawValue)
        activity.title = "Tip Calculator"
        activity.suggestedInvocationPhrase = "Calculate tip"
        activity.isEligibleForPrediction = true
        activity.persistentIdentifier = ShortcutType.tipCalculator.rawValue
        
        let userInfo: [String: Any] = [
            "action": "calculate",
            "type": "tip",
            "billAmount": 100,
            "tipPercentage": 15
        ]
        activity.userInfo = userInfo
        
        self.viewController?.userActivity = activity
        activity.becomeCurrent()
    }
    
    // MARK: - Loan Calculator Shortcut
    private func setupLoanCalculatorShortcut() {
        let activity = NSUserActivity(activityType: ShortcutType.loanCalculator.rawValue)
        activity.title = "Loan Calculator"
        activity.suggestedInvocationPhrase = "Calculate loan"
        activity.isEligibleForPrediction = true
        activity.persistentIdentifier = ShortcutType.loanCalculator.rawValue
        
        let userInfo: [String: Any] = [
            "action": "calculate",
            "type": "loan",
            "principal": 100000,
            "interestRate": 5.0,
            "term": 30
        ]
        activity.userInfo = userInfo
        
        self.viewController?.userActivity = activity
        activity.becomeCurrent()
    }
    
    // MARK: - BMI Calculator Shortcut
    private func setupBMICalculatorShortcut() {
        let activity = NSUserActivity(activityType: ShortcutType.bmiCalculator.rawValue)
        activity.title = "BMI Calculator"
        activity.suggestedInvocationPhrase = "Calculate BMI"
        activity.isEligibleForPrediction = true
        activity.persistentIdentifier = ShortcutType.bmiCalculator.rawValue
        
        let userInfo: [String: Any] = [
            "action": "calculate",
            "type": "bmi",
            "weight": 70,
            "height": 175
        ]
        activity.userInfo = userInfo
        
        self.viewController?.userActivity = activity
        activity.becomeCurrent()
    }
    
    // MARK: - Percentage Calculator Shortcut
    private func setupPercentageCalculatorShortcut() {
        let activity = NSUserActivity(activityType: ShortcutType.percentageCalculator.rawValue)
        activity.title = "Percentage Calculator"
        activity.suggestedInvocationPhrase = "Calculate percentage"
        activity.isEligibleForPrediction = true
        activity.persistentIdentifier = ShortcutType.percentageCalculator.rawValue
        
        let userInfo: [String: Any] = [
            "action": "calculate",
            "type": "percentage",
            "value": 25,
            "total": 100
        ]
        activity.userInfo = userInfo
        
        self.viewController?.userActivity = activity
        activity.becomeCurrent()
    }
    
    // MARK: - Handle Shortcut
    func handleShortcut(_ userActivity: NSUserActivity) {
        guard let userInfo = userActivity.userInfo,
              let action = userInfo["action"] as? String else { return }
        
        switch action {
        case "calculate":
            handleCalculateShortcut(userInfo)
        case "convert":
            handleConvertShortcut(userInfo)
        case "graph":
            handleGraphShortcut(userInfo)
        default:
            break
        }
    }
    
    private func handleCalculateShortcut(_ userInfo: [String: Any]) {
        guard let type = userInfo["type"] as? String else { return }
        
        switch type {
        case "basic":
            navigateToBasicCalculator()
        case "scientific":
            navigateToScientificCalculator()
        case "programmer":
            navigateToProgrammerCalculator()
        case "tip":
            navigateToTipCalculator(userInfo)
        case "loan":
            navigateToLoanCalculator(userInfo)
        case "bmi":
            navigateToBMICalculator(userInfo)
        case "percentage":
            navigateToPercentageCalculator(userInfo)
        default:
            navigateToBasicCalculator()
        }
    }
    
    private func handleConvertShortcut(_ userInfo: [String: Any]) {
        guard let type = userInfo["type"] as? String else { return }
        
        switch type {
        case "units":
            navigateToUnitConverter(userInfo)
        case "currency":
            navigateToCurrencyConverter(userInfo)
        default:
            break
        }
    }
    
    private func handleGraphShortcut(_ userInfo: [String: Any]) {
        navigateToGraphingCalculator(userInfo)
    }
    
    // MARK: - Navigation Methods
    private weak var viewController: UIViewController?
    
    func setViewController(_ viewController: UIViewController) {
        self.viewController = viewController
    }
    
    private func navigateToBasicCalculator() {
        // Navigate to basic calculator tab
        if let tabBarController = viewController?.tabBarController {
            tabBarController.selectedIndex = 0
        }
    }
    
    private func navigateToScientificCalculator() {
        if let tabBarController = viewController?.tabBarController {
            tabBarController.selectedIndex = 1
        }
    }
    
    private func navigateToProgrammerCalculator() {
        if let tabBarController = viewController?.tabBarController {
            tabBarController.selectedIndex = 2
        }
    }
    
    private func navigateToUnitConverter(_ userInfo: [String: Any]) {
        if let tabBarController = viewController?.tabBarController {
            tabBarController.selectedIndex = 3
        }
    }
    
    private func navigateToCurrencyConverter(_ userInfo: [String: Any]) {
        if let tabBarController = viewController?.tabBarController {
            tabBarController.selectedIndex = 4
        }
    }
    
    private func navigateToGraphingCalculator(_ userInfo: [String: Any]) {
        if let tabBarController = viewController?.tabBarController {
            tabBarController.selectedIndex = 5
        }
    }
    
    private func navigateToTipCalculator(_ userInfo: [String: Any]) {
        // Present tip calculator modally
        let tipCalculator = TipCalculatorViewController()
        if let billAmount = userInfo["billAmount"] as? Double {
            tipCalculator.setBillAmount(billAmount)
        }
        viewController?.present(UINavigationController(rootViewController: tipCalculator), animated: true)
    }
    
    private func navigateToLoanCalculator(_ userInfo: [String: Any]) {
        // Present loan calculator modally
        let loanCalculator = LoanCalculatorViewController()
        if let principal = userInfo["principal"] as? Double {
            loanCalculator.setPrincipal(principal)
        }
        viewController?.present(UINavigationController(rootViewController: loanCalculator), animated: true)
    }
    
    private func navigateToBMICalculator(_ userInfo: [String: Any]) {
        // Present BMI calculator modally
        let bmiCalculator = BMICalculatorViewController()
        if let weight = userInfo["weight"] as? Double {
            bmiCalculator.setWeight(weight)
        }
        viewController?.present(UINavigationController(rootViewController: bmiCalculator), animated: true)
    }
    
    private func navigateToPercentageCalculator(_ userInfo: [String: Any]) {
        // Present percentage calculator modally
        let percentageCalculator = PercentageCalculatorViewController()
        if let value = userInfo["value"] as? Double {
            percentageCalculator.setValue(value)
        }
        viewController?.present(UINavigationController(rootViewController: percentageCalculator), animated: true)
    }
    
    // MARK: - Intent Donations
    func donateCalculateIntent(expression: String) {
        let intent = CalculateIntent()
        intent.expression = expression
        
        let interaction = INInteraction(intent: intent, response: nil)
        interaction.identifier = "calculate_\(expression)"
        interaction.donate { error in
            if let error = error {
                print("Failed to donate calculate intent: \(error)")
            }
        }
    }
    
    func donateConvertIntent(fromUnit: String, toUnit: String, value: Double) {
        let intent = ConvertIntent()
        intent.fromUnit = fromUnit
        intent.toUnit = toUnit
        intent.value = NSNumber(value: value)
        
        let interaction = INInteraction(intent: intent, response: nil)
        interaction.identifier = "convert_\(fromUnit)_\(toUnit)"
        interaction.donate { error in
            if let error = error {
                print("Failed to donate convert intent: \(error)")
            }
        }
    }
}

// MARK: - Additional Calculator View Controllers
class TipCalculatorViewController: UIViewController {
    
    private var billAmount: Double = 0
    
    override func viewDidLoad() {
        super.viewDidLoad()
        title = "Tip Calculator"
        view.backgroundColor = CalculatorTheme.shared.backgroundColor
        setupUI()
    }
    
    func setBillAmount(_ amount: Double) {
        billAmount = amount
    }
    
    private func setupUI() {
        // Tip calculator UI implementation
        let stackView = UIStackView()
        stackView.axis = .vertical
        stackView.spacing = 20
        stackView.translatesAutoresizingMaskIntoConstraints = false
        
        let billLabel = UILabel()
        billLabel.text = "Bill: $\(String(format: "%.2f", billAmount))"
        billLabel.font = UIFont.systemFont(ofSize: 24, weight: .bold)
        billLabel.textColor = CalculatorTheme.shared.textColor
        
        let tip15Label = UILabel()
        tip15Label.text = "15% Tip: $\(String(format: "%.2f", billAmount * 0.15))"
        tip15Label.textColor = CalculatorTheme.shared.textColor
        
        let tip20Label = UILabel()
        tip20Label.text = "20% Tip: $\(String(format: "%.2f", billAmount * 0.20))"
        tip20Label.textColor = CalculatorTheme.shared.textColor
        
        let tip25Label = UILabel()
        tip25Label.text = "25% Tip: $\(String(format: "%.2f", billAmount * 0.25))"
        tip25Label.textColor = CalculatorTheme.shared.textColor
        
        [billLabel, tip15Label, tip20Label, tip25Label].forEach {
            $0.textAlignment = .center
            stackView.addArrangedSubview($0)
        }
        
        view.addSubview(stackView)
        
        NSLayoutConstraint.activate([
            stackView.centerXAnchor.constraint(equalTo: view.centerXAnchor),
            stackView.centerYAnchor.constraint(equalTo: view.centerYAnchor),
            stackView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 20),
            stackView.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -20)
        ])
    }
}

class LoanCalculatorViewController: UIViewController {
    
    private var principal: Double = 0
    
    override func viewDidLoad() {
        super.viewDidLoad()
        title = "Loan Calculator"
        view.backgroundColor = CalculatorTheme.shared.backgroundColor
        setupUI()
    }
    
    func setPrincipal(_ amount: Double) {
        principal = amount
    }
    
    private func setupUI() {
        // Loan calculator UI implementation
        let stackView = UIStackView()
        stackView.axis = .vertical
        stackView.spacing = 20
        stackView.translatesAutoresizingMaskIntoConstraints = false
        
        let principalLabel = UILabel()
        principalLabel.text = "Principal: $\(String(format: "%.2f", principal))"
        principalLabel.font = UIFont.systemFont(ofSize: 24, weight: .bold)
        principalLabel.textColor = CalculatorTheme.shared.textColor
        
        let monthlyPaymentLabel = UILabel()
        let monthlyPayment = calculateMonthlyPayment()
        monthlyPaymentLabel.text = "Monthly Payment: $\(String(format: "%.2f", monthlyPayment))"
        monthlyPaymentLabel.textColor = CalculatorTheme.shared.textColor
        
        [principalLabel, monthlyPaymentLabel].forEach {
            $0.textAlignment = .center
            stackView.addArrangedSubview($0)
        }
        
        view.addSubview(stackView)
        
        NSLayoutConstraint.activate([
            stackView.centerXAnchor.constraint(equalTo: view.centerXAnchor),
            stackView.centerYAnchor.constraint(equalTo: view.centerYAnchor),
            stackView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 20),
            stackView.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -20)
        ])
    }
    
    private func calculateMonthlyPayment() -> Double {
        let interestRate = 0.05 // 5%
        let term = 30 * 12 // 30 years in months
        
        if interestRate == 0 {
            return principal / Double(term)
        }
        
        let monthlyRate = interestRate / 12
        return principal * (monthlyRate * pow(1 + monthlyRate, Double(term))) / (pow(1 + monthlyRate, Double(term)) - 1)
    }
}

class BMICalculatorViewController: UIViewController {
    
    private var weight: Double = 0
    private var height: Double = 0
    
    override func viewDidLoad() {
        super.viewDidLoad()
        title = "BMI Calculator"
        view.backgroundColor = CalculatorTheme.shared.backgroundColor
        setupUI()
    }
    
    func setWeight(_ value: Double) {
        weight = value
    }
    
    func setHeight(_ value: Double) {
        height = value
    }
    
    private func setupUI() {
        let stackView = UIStackView()
        stackView.axis = .vertical
        stackView.spacing = 20
        stackView.translatesAutoresizingMaskIntoConstraints = false
        
        let weightLabel = UILabel()
        weightLabel.text = "Weight: \(weight) kg"
        weightLabel.font = UIFont.systemFont(ofSize: 20)
        weightLabel.textColor = CalculatorTheme.shared.textColor
        
        let heightLabel = UILabel()
        heightLabel.text = "Height: \(height) cm"
        heightLabel.font = UIFont.systemFont(ofSize: 20)
        heightLabel.textColor = CalculatorTheme.shared.textColor
        
        let bmiLabel = UILabel()
        let bmi = calculateBMI()
        bmiLabel.text = "BMI: \(String(format: "%.1f", bmi))"
        bmiLabel.font = UIFont.systemFont(ofSize: 24, weight: .bold)
        bmiLabel.textColor = CalculatorTheme.shared.textColor
        
        let categoryLabel = UILabel()
        categoryLabel.text = getBMICategory(bmi)
        categoryLabel.font = UIFont.systemFont(ofSize: 18)
        categoryLabel.textColor = CalculatorTheme.shared.textColor
        
        [weightLabel, heightLabel, bmiLabel, categoryLabel].forEach {
            $0.textAlignment = .center
            stackView.addArrangedSubview($0)
        }
        
        view.addSubview(stackView)
        
        NSLayoutConstraint.activate([
            stackView.centerXAnchor.constraint(equalTo: view.centerXAnchor),
            stackView.centerYAnchor.constraint(equalTo: view.centerYAnchor),
            stackView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 20),
            stackView.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -20)
        ])
    }
    
    private func calculateBMI() -> Double {
        let heightInMeters = height / 100
        return weight / (heightInMeters * heightInMeters)
    }
    
    private func getBMICategory(_ bmi: Double) -> String {
        switch bmi {
        case ..<18.5:
            return "Underweight"
        case 18.5..<25:
            return "Normal weight"
        case 25..<30:
            return "Overweight"
        default:
            return "Obese"
        }
    }
}

class PercentageCalculatorViewController: UIViewController {
    
    private var value: Double = 0
    
    override func viewDidLoad() {
        super.viewDidLoad()
        title = "Percentage Calculator"
        view.backgroundColor = CalculatorTheme.shared.backgroundColor
        setupUI()
    }
    
    func setValue(_ val: Double) {
        value = val
    }
    
    private func setupUI() {
        let stackView = UIStackView()
        stackView.axis = .vertical
        stackView.spacing = 20
        stackView.translatesAutoresizingMaskIntoConstraints = false
        
        let valueLabel = UILabel()
        valueLabel.text = "\(value)% of 100 = \(value)"
        valueLabel.font = UIFont.systemFont(ofSize: 24, weight: .bold)
        valueLabel.textColor = CalculatorTheme.shared.textColor
        
        [valueLabel].forEach {
            $0.textAlignment = .center
            stackView.addArrangedSubview($0)
        }
        
        view.addSubview(stackView)
        
        NSLayoutConstraint.activate([
            stackView.centerXAnchor.constraint(equalTo: view.centerXAnchor),
            stackView.centerYAnchor.constraint(equalTo: view.centerYAnchor),
            stackView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 20),
            stackView.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -20)
        ])
    }
}
656 lines•23.5 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