码迷,mamicode.com
首页 > 其他好文 > 详细

Xcode 制作简易计算器

时间:2014-07-16 20:38:30      阅读:355      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   os   2014   

bubuko.com,布布扣

bubuko.com,布布扣

bubuko.com,布布扣

#import "ViewController.h"

#import "jsq.h"

@interface ViewController () @property (weak, nonatomic) IBOutlet UILabel *label; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; jsqq = [[jsq alloc] init]; //初始化对象jsqq } - (IBAction)v:(UIButton *)sender { if(jsqq.op==0) //判断是否已经按了运算符 { jsqq.op1 = jsqq.op1*10 + sender.tag; self.label.text = [NSString stringWithFormat:@"%f",jsqq.op1]; //将浮点数转化为字符串,并显示在label上 } else { jsqq.op2 = jsqq.op2*10 + sender.tag; self.label.text = [NSString stringWithFormat:@"%f",jsqq.op2]; } } - (IBAction)c:(UIButton *)sender { if(sender.tag==11) { self.label.text =@"+";//在label上显示字符“+” jsqq.op = +; } else if(sender.tag==12) { self.label.text =@"-"; jsqq.op = -; } else if(sender.tag==13) { self.label.text =@"*"; jsqq.op = *; } else if(sender.tag==14) { self.label.text =@"/"; jsqq.op = /; } else if(sender.tag==15) //“=”键 { float resurt; if(jsqq.op == +){ resurt = [jsqq add]; //调用方法,算出结果 } else if(jsqq.op == -){ resurt = [jsqq sub]; } else if(jsqq.op == *){ resurt = [jsqq mu]; } else if(jsqq.op == /){ resurt = [jsqq div]; } self.label.text = [NSString stringWithFormat:@"%f",resurt]; jsqq.op1 = resurt; jsqq.op2 = 0; } else if(sender.tag==16) //清零 “c”键 { jsqq.op = 0; jsqq.op1 = 0; jsqq.op2 = 0; self.label.text =@"0"; } } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end

 

 

实现的效果如下:

bubuko.com,布布扣

Xcode 制作简易计算器,布布扣,bubuko.com

Xcode 制作简易计算器

标签:style   blog   http   color   os   2014   

原文地址:http://www.cnblogs.com/baiying/p/3836638.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!