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

iOS實(shí)現(xiàn)簡單計(jì)算器小功能

 更新時(shí)間:2022年01月28日 07:34:11   作者:踏實(shí)做好每件小事  
這篇文章主要為大家詳細(xì)介紹了iOS實(shí)現(xiàn)簡單計(jì)算器功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

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

SimpleCaculatorViewController.h

//
// ?SimpleCaculatorViewController.h
// ?SimpleCaculator
//
// ?Created by LI Junui on 14-2-12.
// ?Copyright (c) 2014年 LEE JUNHUI. All rights reserved.
//
?
#import <UIKit/UIKit.h>
?
@interface SimpleCaculatorViewController : UIViewController
@property (weak, nonatomic) IBOutlet UILabel *displayScreen;
- (IBAction)numberBtnClick:(UIButton *)sender;
- (IBAction)clearDS:(UIButton *)sender;
- (IBAction)caculate:(UIButton *)sender;
- (IBAction)hint:(UIButton *)sender;
- (IBAction)act:(UIButton *)sender;
- (IBAction)clearBack:(UIButton *)sender;
?
?
?
@property(assign, nonatomic) BOOL isUserInputingNumber;
@property(assign, nonatomic) int num1;
@property(assign, nonatomic) int num2;
@property(assign, nonatomic) int tagForAct;
?
@end

SimpleCaculatorViewController.m

//
// ?SimpleCaculatorViewController.m
// ?SimpleCaculator
//
// ?Created by LI Junui on 14-2-12.
// ?Copyright (c) 2014年 LEE JUNHUI. All rights reserved.
//
?
#import "SimpleCaculatorViewController.h"
?
@interface SimpleCaculatorViewController ()
?
@end
?
@implementation SimpleCaculatorViewController
?
//記錄數(shù)字按鈕點(diǎn)擊事件
- (IBAction)numberBtnClick:(UIButton *)sender {
? ??
? ? if(self.isUserInputingNumber){
? ? ? ? int re = [_displayScreen.text intValue] * 10 + [sender.currentTitle intValue];
? ? ? ? _displayScreen.text = [NSString stringWithFormat:@"%d",re];
? ? } else{
? ? ? ? [_displayScreen setText:sender.currentTitle];
? ? ? ? _isUserInputingNumber = YES;//因?yàn)榈谝淮芜M(jìn)入程序會(huì)輸入數(shù)字,因此為YES
? ? }
}
?
//清零操作
- (IBAction)clearDS:(UIButton *)sender {
? ??
? ? _displayScreen.text = @"0";
? ? _isUserInputingNumber = NO;//表示沒有再輸入了
}
?
//得到結(jié)果
- (IBAction)caculate:(UIButton *)sender {
? ? int re = 0;
? ? _num2 = [_displayScreen.text intValue];
? ? switch (_tagForAct) {
? ? ? ? case 1: //加法
? ? ? ? ? ? re = _num1 + _num2;
? ? ? ? ? ? break;
? ? ? ? case 2: //減法
? ? ? ? ? ? re = _num1 - _num2;
? ? ? ? ? ? break;
? ? ? ? case 3: //乘法
? ? ? ? ? ? re = _num1 * _num2;
? ? ? ? ? ? break;
? ? ? ? case 4: //除法
? ? ? ? ? ? re = _num1 / _num2;
? ? ? ? ? ? break;
? ? }
? ? _displayScreen.text = [NSString stringWithFormat:@"=%d", re];
? ? _num1 = 0;
? ? _num2 = 0;
}
?
//彈出提示對話框
- (IBAction)hint:(UIButton *)sender {
? ? UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"溫馨提示" message:@"本計(jì)算器由LJH出品" delegate:self cancelButtonTitle:@"返回" otherButtonTitles: nil];
? ? [alert show];
}
?
//進(jìn)行四則運(yùn)算
- (IBAction)act:(UIButton *)sender {
? ? //1.得到_displayScreen上的數(shù)字
? ? _num1 = [_displayScreen.text intValue];
? ? _displayScreen.text = sender.currentTitle;
? ? _isUserInputingNumber =YES;
? ? switch (sender.tag) {
? ? ? ? case 1: //加法
? ? ? ? ? ? _tagForAct = 1;
? ? ? ? ? ? break;
? ? ? ? case 2: //減法
? ? ? ? ? ? _tagForAct = 2;
? ? ? ? ? ? break;
? ? ? ? case 3: //乘法
? ? ? ? ? ? _tagForAct = 3;
? ? ? ? ? ? break;
? ? ? ? case 4: //除法
? ? ? ? ? ? _tagForAct = 4;
? ? ? ? ? ? break;
? ? }
}
?
//進(jìn)行回刪操作
- (IBAction)clearBack:(UIButton *)sender {
? ? int length = [_displayScreen.text length];
? ? int temp = [_displayScreen.text intValue];
? ? temp = temp/length;
}
@end

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

相關(guān)文章

  • React Native搭建iOS開發(fā)環(huán)境

    React Native搭建iOS開發(fā)環(huán)境

    React Native的門檻不管是對于前端開發(fā)者還是移動(dòng)端開發(fā)者來說都是很高的,既要懂原生又要懂js,技術(shù)棧是相當(dāng)長的。但是沒有關(guān)系,下面我們一步步來學(xué)習(xí),慢慢成長吧!
    2016-09-09
  • 兩種iOS隱藏導(dǎo)航欄的正確方法

    兩種iOS隱藏導(dǎo)航欄的正確方法

    這篇文章主要為大家詳細(xì)介紹了iOS導(dǎo)航欄的正確隱藏方式,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-03-03
  • iOS封裝倒計(jì)時(shí)按鈕HLCountDownButton示例詳解

    iOS封裝倒計(jì)時(shí)按鈕HLCountDownButton示例詳解

    這篇文章主要為大家介紹了iOS封裝倒計(jì)時(shí)按鈕HLCountDownButton示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-07-07
  • iOS WKWebView無法處理URL Scheme和App Store鏈接的問題解決

    iOS WKWebView無法處理URL Scheme和App Store鏈接的問題解決

    這篇文章主要給大家介紹了關(guān)于iOS WKWebView無法處理URL Scheme和App Store鏈接的問題解決的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。
    2018-03-03
  • iOS開發(fā)之隱藏導(dǎo)航欄線的簡單代碼

    iOS開發(fā)之隱藏導(dǎo)航欄線的簡單代碼

    這篇文章主要介紹了iOS開發(fā)之隱藏導(dǎo)航欄線的簡單代碼,需要的朋友可以參考下
    2017-10-10
  • iOS多控制器實(shí)現(xiàn)帶滑動(dòng)動(dòng)畫

    iOS多控制器實(shí)現(xiàn)帶滑動(dòng)動(dòng)畫

    這篇文章主要為大家詳細(xì)介紹了iOS多控制器實(shí)現(xiàn)帶滑動(dòng)動(dòng)畫,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-06-06
  • iOS時(shí)間字符串格式化輸出技巧詳解

    iOS時(shí)間字符串格式化輸出技巧詳解

    本篇文章主要介紹了iOS時(shí)間格式化輸出技巧,可以將后臺(tái)返回的時(shí)間字符串轉(zhuǎn)換為指定的格式時(shí)間再顯示在UI上,有興趣的可以了解一下。
    2017-04-04
  • iOS10全新推送功能實(shí)現(xiàn)代碼

    iOS10全新推送功能實(shí)現(xiàn)代碼

    這篇文章主要為大家詳細(xì)介紹了iOS10全新推送功能實(shí)現(xiàn)代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-09-09
  • 詳解使用Xcode7的Instruments檢測解決iOS內(nèi)存泄露(最新)

    詳解使用Xcode7的Instruments檢測解決iOS內(nèi)存泄露(最新)

    本篇文章主要介紹使用Xcode7的Instruments檢測解決iOS內(nèi)存泄露(最新)的相關(guān)資料,需要的朋友可以參考下
    2017-09-09
  • ios學(xué)習(xí)筆記之基礎(chǔ)數(shù)據(jù)類型的轉(zhuǎn)換

    ios學(xué)習(xí)筆記之基礎(chǔ)數(shù)據(jù)類型的轉(zhuǎn)換

    在編碼過程中,數(shù)據(jù)的處理是必要的。眾多數(shù)據(jù)中,NSString、NSData、NSArray、 NSDictionary等數(shù)據(jù)類型是常用的,對付它們?nèi)菀?,但是在多個(gè)數(shù)據(jù)類型之間轉(zhuǎn)換就需要技巧了。本文主要給大家介紹ios中基礎(chǔ)數(shù)據(jù)類型的轉(zhuǎn)換,有需要的下面來一起看看吧。
    2016-11-11

最新評論

宜兴市| 惠安县| 东莞市| 乌兰察布市| 伊春市| 桦川县| 石首市| 桂阳县| 米林县| 石嘴山市| 曲沃县| 临邑县| 民权县| 永川市| 色达县| 富平县| 双柏县| 汶上县| 阜宁县| 集贤县| 长子县| 环江| 浏阳市| 梁山县| 岳普湖县| 辽源市| 正定县| 吐鲁番市| 玉山县| 扶余县| 赤壁市| 松原市| 聊城市| 景宁| 博白县| 广德县| 郁南县| 海林市| 三明市| 莱州市| 桃源县|