zoukankan      html  css  js  c++  java
  • Xcode 简易计算器 (修改版)

    
    
    主要代码:

    #import
    "ViewController.h" #import "jsq.h" @interface ViewController () @property (weak, nonatomic) IBOutlet UILabel *label; @end float n = 10; float resurt; @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; jsqq = [[jsq alloc] init]; //初始化对象jsqq UIImage *image1 = [UIImage imageNamed:@"1.png"]; UIImage *image2 = [UIImage imageNamed:@"2.png"]; UIImage *image3 = [UIImage imageNamed:@"3.png"]; UIImage *image4 = [UIImage imageNamed:@"4.png"]; UIImageView *imageView1 = [[UIImageView alloc] initWithFrame:CGRectMake(135, 370, 180, 110)]; NSArray *array = [NSArray arrayWithObjects:image1,image2,image3,image4, nil]; //创建一个OC的数组,并且设置它里面的元素 imageView1.animationDuration = 1; //动画执行的时长,单位为秒 imageView1.animationImages = array; //动画图片数组 //imageView1.animationRepeatCount = 2;//重复次数,默认为无限循环 [imageView1 startAnimating]; //开始执行动画 [self.view addSubview:imageView1]; } - (IBAction)v:(UIButton *)sender { if(jsqq.op==0) //判断是否已经按了运算符 { if (jsqq.dot == '.'){ jsqq.op1 = sender.tag/n + jsqq.op1; n = n *10; } else{ jsqq.op1 = jsqq.op1*10 + sender.tag; } self.label.text = [NSString stringWithFormat:@"%.4f",jsqq.op1]; //将浮点数转化为字符串,并显示在label上 } else { if (jsqq.dot == '.'){ jsqq.op2 = sender.tag /n + jsqq.op2; n = n *10; } else{ jsqq.op2 = jsqq.op2*10 + sender.tag; } self.label.text = [NSString stringWithFormat:@"%.4f",jsqq.op2]; } } - (IBAction)c:(UIButton *)sender { jsqq.dot=0; n = 10; switch (sender.tag) { case 11: jsqq.op = '+'; break; case 12: jsqq.op = '-'; break; case 13: jsqq.op = '*'; break; case 14: jsqq.op = '/'; break; case 16: jsqq.op = 0; jsqq.op1 = 0; jsqq.op2 = 0; jsqq.dot = 0; n = 10; self.label.text =@"0"; break; default: break; } } - (IBAction)d:(id)sender { resurt = [jsqq work]; self.label.text = [NSString stringWithFormat:@"%.4f",resurt]; jsqq.op1 = resurt; jsqq.op2 = 0; jsqq.dot = 0; } - (IBAction)dot:(id)sender { jsqq.dot = '.'; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end

    实现的效果如下:

  • 相关阅读:
    C# 参数按照ASCII码从小到大排序(字典序)
    .net平台下C#socket通信 (下)
    net平台下C#socket通信(上)
    使用C#创建Windows服务
    C# EF 批量操作
    消息队列及常见消息队列介绍
    消息队列的4种应用场景
    npm install 安装到指定的目录
    express学习1
    nodejs url
  • 原文地址:https://www.cnblogs.com/baiying/p/3836638.html
Copyright © 2011-2022 走看看