嗨,我正在尝试将美元和欧元转换为货币
我宣布单选按钮为 radioUSD radioEUR
,我想为单选按钮分配一个值 radioUSD = 0.395 radioEUR = 0.447
我是可可的新手
我尝试了很多在线解决方案,但是没有用
进口可可粉
ViewController类:NSViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
@IBOutlet weak var radioUSD: NSButton!
@IBOutlet weak var radioEUR: NSButton!
@IBOutlet weak var Label: NSTextField!
@IBOutlet weak var value: NSTextField!
var us = 0.395
var eur = 0.447
@IBAction func calc(_ sender: Any) {
Label.doubleValue = value.doubleValue * us
}
override var representedObject: Any? {
didSet {
// Update the view, if already loaded.
}
}
}
如果我选择,我希望输出是 美元值* 0.395 对于我们的值* 0.447
答案 0 :(得分:0)
//
// ViewController.swift
// Currency Converter
//
// Create`enter code here`d by Firas Albusaidy on 6/30/19.
// Copyright © 2019 Firas Albusaidy. All rights reserved.
//
import Cocoa
class ViewController: NSViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
@IBOutlet weak var radioUSD: NSButton!
@IBOutlet weak var radioEUR: NSButton!
@IBOutlet weak var Label: NSTextField!
@IBOutlet weak var value: NSTextField!
var us = 0.395
var eur = 0.447
@IBAction func calc(_ sender: Any) {
if (radioUSD.state == NSControl.StateValue(rawValue: 1))
{
Label.doubleValue = value.doubleValue * us
print ("Radio 1 Selected");
}
else
{
Label.doubleValue = value.doubleValue * eur
print ("Radio 2 Selected");
}
}
override var representedObject: Any? {
didSet {
// Update the view, if already loaded.
}
}
}