最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

swift實(shí)現(xiàn)簡易計(jì)算器項(xiàng)目

 更新時(shí)間:2022年01月27日 11:17:28   作者:luoppusheng  
這篇文章主要為大家詳細(xì)介紹了swift實(shí)現(xiàn)簡易計(jì)算器項(xiàng)目,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了swift實(shí)現(xiàn)簡易計(jì)算器的具體代碼,供大家參考,具體內(nèi)容如下

首先在storyboard中搭建出界面

接著上viewcontroller代碼

import UIKit

class ViewController: UIViewController {
? ? @IBOutlet weak var result: UILabel!


? ? var n1: String = ""
? ? var n2: String = ""
? ? var n3: String = ""

? ? override func viewDidLoad() {
? ? ? ? super.viewDidLoad()
? ? ? ? // Do any additional setup after loading the view, typically from a nib.

? ? }


? ? override func didReceiveMemoryWarning() {
? ? ? ? super.didReceiveMemoryWarning()

? ? ? ? // Dispose of any resources that can be recreated.

? ? }


? ? @IBAction func didClick(sender: UIButton) {
? ? ? ? let temp = sender.currentTitle

? ? ? ? if temp == "AC" {
? ? ? ? ? ? n1 = ""
? ? ? ? ? ? n2 = ""

? ? ? ? ? result.text = "0"
? ? ? ? ? ? return

? ? ? ? }

? ? ? ? else if temp == "+" || temp == "-" || temp == "*" || temp == "/" {
? ? ? ? ? n1 = result.text!
? ? ? ? ? n2 = ""
? ? ? ? ? n3 = temp!

? ? ? ? ? return

? ? ? ? }

? ? ? ? else if temp == "=" {
? ? ? ? ? ? var result1: Double = 0
? ? ? ? ? ? ? ?println("n1:"+n1+" n2:"+n2)

? ? ? ? ? ? switch n3 {
? ? ? ? ? ? ?case "+":
? ? ? ? ? ? ? ? result1 = (n1 as NSString).doubleValue + (n2 as NSString).doubleValue ? ? ? ? ?
? ? ? ? ? ? ?case "-":
? ? ? ? ? ? ? ? result1 = (n1 as NSString).doubleValue - (n2 as NSString).doubleValue
?
? ? ? ? ? ? ?case "*":
? ? ? ? ? ? ? ? result1 = (n1 as NSString).doubleValue * (n2 as NSString).doubleValue
? ? ? ? ? ? ?case "/":
? ? ? ? ? ? ? ? result1 = (n1 as NSString).doubleValue / (n2 as NSString).doubleValue
? ? ? ? ? ? ?default:
? ? ? ? ? ? ? ? result1 = 0

? ? ? ? ? ? }

? ? ? ? ? ? result.text = "\(result1)"
? ? ? ? ? ? n3 = ""
? ? ? ? ? ? return? ? ? ? ? ??

? ? ? ? }
? ? ? ??
? ? ? ? if n3 != "" {
? ? ? ? ? n2 = n2 + temp!

? ? ? ? ? result.text = n2

? ? ? ? }else {
? ? ? ? ? n1 = n1 + temp!

? ? ? ? ? result.text = n1


? ? ? ? }


? ? }


}

最后效果圖

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論

万盛区| 洞头县| 连平县| 泊头市| 双流县| 贡嘎县| 饶平县| 法库县| 新绛县| 多伦县| 河津市| 临猗县| 台东县| 方山县| 灯塔市| 丰台区| 哈尔滨市| 临沭县| 梅州市| 醴陵市| 阳东县| 奉新县| 益阳市| 晋江市| 南靖县| 买车| 思南县| 连江县| 东阳市| 通化县| 东方市| 宁德市| 永登县| 子洲县| 海丰县| 张北县| 长沙县| 英吉沙县| 镇宁| 樟树市| 兰州市|