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

swift實現(xiàn)簡易計算器項目

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

本文實例為大家分享了swift實現(xiàn)簡易計算器的具體代碼,供大家參考,具體內(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)文章

最新評論

应城市| 同德县| 奇台县| 辽阳县| 申扎县| 额尔古纳市| 嘉鱼县| 平安县| 游戏| 西华县| 曲麻莱县| 高邮市| 江门市| 泾川县| 温泉县| 甘谷县| 高尔夫| 新闻| 荥经县| 宜宾县| 玛沁县| 衡阳县| 阳江市| 封开县| 荣成市| 嵊州市| 江城| 昌吉市| 富民县| 高要市| 宕昌县| 陈巴尔虎旗| 宁海县| 定日县| 安溪县| 正宁县| 彩票| 德惠市| 延安市| 繁昌县| 荔浦县|