欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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;
}
?
//彈出提示對(duì)話框
- (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)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

  • iOS中多線程的入門使用教程(Swift)

    iOS中多線程的入門使用教程(Swift)

    這篇文章主要給大家介紹了關(guān)于iOS中多線程入門使用的相關(guān)資料,一個(gè)進(jìn)程中可以開啟多條線程,每條線程可以并行執(zhí)行不同的任務(wù),本文通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2021-11-11
  • IOS生成與讀取二維碼名片

    IOS生成與讀取二維碼名片

    這篇文章主要為大家介紹了IOS生成與讀取二維碼名片的方法,感興趣的小伙伴們可以參考一下
    2016-01-01
  • 基于iOS實(shí)現(xiàn)倒影效果

    基于iOS實(shí)現(xiàn)倒影效果

    這篇文章主要為大家詳細(xì)介紹了基于iOS實(shí)現(xiàn)倒影效果的相關(guān)代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-07-07
  • iOS實(shí)現(xiàn)播放遠(yuǎn)程網(wǎng)絡(luò)音樂的核心技術(shù)點(diǎn)總結(jié)

    iOS實(shí)現(xiàn)播放遠(yuǎn)程網(wǎng)絡(luò)音樂的核心技術(shù)點(diǎn)總結(jié)

    本篇文章主要介紹了iOS播放遠(yuǎn)程網(wǎng)絡(luò)音樂的核心技術(shù),采用ios系統(tǒng)自帶的AVFoundation框架來實(shí)現(xiàn),有需要的朋友可以了解一下。
    2016-11-11
  • iOS開發(fā)中判斷字符串為空的方法

    iOS開發(fā)中判斷字符串為空的方法

    判斷字符串為空,看著很簡單,其實(shí)不然,下面通過本篇文章給大家介紹了iOS開發(fā)中判斷字符串為空的方法,需要的朋友可以參考下
    2017-12-12
  • IOS實(shí)現(xiàn)左右兩個(gè)TableView聯(lián)動(dòng)效果

    IOS實(shí)現(xiàn)左右兩個(gè)TableView聯(lián)動(dòng)效果

    在我們?nèi)粘i_發(fā)IOS中,經(jīng)常見到兩個(gè)tableview的聯(lián)動(dòng),滑動(dòng)一側(cè)tableview,另一側(cè)tableview跟著滑動(dòng),其實(shí)實(shí)現(xiàn)起來比較簡單,只是需要搞清楚他們之間的區(qū)別和聯(lián)系,下面一起來看看如何實(shí)現(xiàn)。
    2016-08-08
  • iOS利用NSAttributedString實(shí)現(xiàn)圖文混排效果示例

    iOS利用NSAttributedString實(shí)現(xiàn)圖文混排效果示例

    iOS7以后,因?yàn)門extKit的強(qiáng)大,可以用NSAttributedString很方便的實(shí)現(xiàn)圖文混排(主要是利用了NSTextAttachment),所以下面這篇文章主要給大家介紹了關(guān)于iOS利用NSAttributedString實(shí)現(xiàn)圖文混排效果的相關(guān)資料,需要的朋友可以參考借鑒,下面來一起看看吧。
    2017-10-10
  • iOS實(shí)現(xiàn)實(shí)時(shí)檢測(cè)網(wǎng)絡(luò)狀態(tài)的示例代碼

    iOS實(shí)現(xiàn)實(shí)時(shí)檢測(cè)網(wǎng)絡(luò)狀態(tài)的示例代碼

    網(wǎng)絡(luò)連接狀態(tài)檢測(cè)對(duì)于我們的iOS開發(fā)來說是一個(gè)非常通用的需求。下面這篇文章主要就給大家介紹了關(guān)于利用iOS實(shí)現(xiàn)實(shí)時(shí)檢測(cè)網(wǎng)絡(luò)狀態(tài)的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起看看吧。
    2017-07-07
  • iOS自定義相機(jī)實(shí)現(xiàn)拍照、錄制視頻

    iOS自定義相機(jī)實(shí)現(xiàn)拍照、錄制視頻

    這篇文章主要為大家詳細(xì)介紹了iOS自定義相機(jī)實(shí)現(xiàn)拍照、錄制視頻,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-04-04
  • 最新評(píng)論