计算器(没写完呢)
来源:互联网 发布:天龙绿色食品网络交易 编辑:程序博客网 时间:2024/04/28 11:10
UILabel *plusLable = [[UILabel alloc] initWithFrame:CGRectMake(40, 40, 200, 40)];
plusLable.backgroundColor = [UIColor whiteColor];
plusLable.textAlignment = NSTextAlignmentRight; //所显示的文本内容位置
plusLable.tag = 100;
[self.window addSubview:plusLable];
[plusLable release];
UIButton *a1Button= [UIButton buttonWithType: UIButtonTypeRoundedRect];
a1Button.frame = CGRectMake(40, 100, 40, 40);
[a1Button setTitle:@"1" forState:UIControlStateNormal];
a1Button.backgroundColor = [UIColor blackColor];
[a1Button addTarget:self action:@selector(plus1:) forControlEvents:UIControlEventTouchUpInside];
[self.window addSubview:a1Button];
UIButton *a2Button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
a2Button.frame = CGRectMake(120, 100, 40, 40);
[a2Button setTitle:@"2" forState:UIControlStateNormal];
a2Button.backgroundColor = [UIColor blackColor];
[a2Button addTarget:self action:@selector(plus1:) forControlEvents:UIControlEventTouchUpInside];
[self.window addSubview:a2Button];
UIButton *a3Button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
a3Button.frame = CGRectMake(200, 100, 40, 40);
[a3Button setTitle:@"3" forState:UIControlStateNormal];
a3Button.backgroundColor = [UIColor blackColor];
[a3Button addTarget:self action:@selector(plus1:) forControlEvents:UIControlEventTouchUpInside];
[self.window addSubview:a3Button];
UIButton *a4Button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
a4Button.frame = CGRectMake(40,160, 40, 40);
[a4Button setTitle:@"4" forState:UIControlStateNormal];
a4Button.backgroundColor = [UIColor blackColor];
[a4Button addTarget:self action:@selector(plus1:) forControlEvents:UIControlEventTouchUpInside];
[self.window addSubview:a4Button];
UIButton *a5Button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
a5Button.frame = CGRectMake(120, 160, 40, 40);
[a5Button setTitle:@"5" forState:UIControlStateNormal];
a5Button.backgroundColor = [UIColor blackColor];
[a5Button addTarget:self action:@selector(plus1:) forControlEvents:UIControlEventTouchUpInside];
[self.window addSubview:a5Button];
UIButton*a6Button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
a6Button.frame = CGRectMake(200, 160, 40, 40);
[a6Button setTitle:@"6" forState:UIControlStateNormal];
a6Button.backgroundColor = [UIColor blackColor];
[a6Button addTarget:self action:@selector(plus1:) forControlEvents:UIControlEventTouchUpInside];
[self.window addSubview:a6Button];
UIButton *a7Button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
a7Button.frame = CGRectMake(40,220, 40, 40);
[a7Button setTitle:@"7" forState:UIControlStateNormal];
a7Button.backgroundColor = [UIColor blackColor];
[a7Button addTarget:self action:@selector(plus1:) forControlEvents:UIControlEventTouchUpInside];
[self.window addSubview:a7Button];
UIButton *a8Button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
a8Button.frame = CGRectMake(120, 220, 40, 40);
[a8Button setTitle:@"8" forState:UIControlStateNormal];
a8Button.backgroundColor = [UIColor blackColor];
[a8Button addTarget:self action:@selector(plus1:) forControlEvents:UIControlEventTouchUpInside];
[self.window addSubview:a8Button];
UIButton * a9Button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
a9Button.frame = CGRectMake(200, 220, 40, 40);
[a9Button setTitle:@"9" forState:UIControlStateNormal];
a9Button.backgroundColor = [UIColor blackColor];
[a9Button addTarget:self action:@selector(plus1:) forControlEvents:UIControlEventTouchUpInside];
[self.window addSubview:a9Button];
UIButton *dyButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
dyButton.frame = CGRectMake(260, 100, 40, 40);
[dyButton setTitle:@"=" forState:UIControlStateNormal];
dyButton.backgroundColor = [UIColor blackColor];
[dyButton addTarget:self action:@selector(plus1:) forControlEvents:UIControlEventTouchUpInside];
[self.window addSubview:dyButton];
UIButton *sumButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
sumButton.frame = CGRectMake(260, 160, 40, 40);
[sumButton setTitle:@"+" forState:UIControlStateNormal];
sumButton.backgroundColor = [UIColor blackColor];
[sumButton addTarget:self action:@selector(plus1:) forControlEvents:UIControlEventTouchUpInside];
[self.window addSubview:sumButton];
UIButton *jfButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
jfButton.frame = CGRectMake(260, 220, 40, 40);
[jfButton setTitle:@"-" forState:UIControlStateNormal];
jfButton.backgroundColor = [UIColor blackColor];
[sumButton addTarget:self action:@selector(plus1:) forControlEvents:UIControlEventTouchUpInside];
[self.window addSubview:jfButton];
return YES;
}
- (void)plus1:(UIButton *)button
{
int sum = 0 ;
NSString *number1 =[button titleForState:UIControlStateNormal];
UILabel *lable= (UILabel *)[self.window viewWithTag:100];
int number = number1.intValue;
if (number >= 0 && number <= 9) {
lable.text = number1 ;
}
if ([number1 isEqualToString:@"+"]) {
sum += number;
}
if ([number1 isEqualToString:@"="]) {
lable.text = [NSString stringWithFormat:@"%d", sum];
}
}
plusLable.backgroundColor = [UIColor whiteColor];
plusLable.textAlignment = NSTextAlignmentRight; //所显示的文本内容位置
plusLable.tag = 100;
[self.window addSubview:plusLable];
[plusLable release];
UIButton *a1Button= [UIButton buttonWithType: UIButtonTypeRoundedRect];
a1Button.frame = CGRectMake(40, 100, 40, 40);
[a1Button setTitle:@"1" forState:UIControlStateNormal];
a1Button.backgroundColor = [UIColor blackColor];
[a1Button addTarget:self action:@selector(plus1:) forControlEvents:UIControlEventTouchUpInside];
[self.window addSubview:a1Button];
UIButton *a2Button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
a2Button.frame = CGRectMake(120, 100, 40, 40);
[a2Button setTitle:@"2" forState:UIControlStateNormal];
a2Button.backgroundColor = [UIColor blackColor];
[a2Button addTarget:self action:@selector(plus1:) forControlEvents:UIControlEventTouchUpInside];
[self.window addSubview:a2Button];
UIButton *a3Button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
a3Button.frame = CGRectMake(200, 100, 40, 40);
[a3Button setTitle:@"3" forState:UIControlStateNormal];
a3Button.backgroundColor = [UIColor blackColor];
[a3Button addTarget:self action:@selector(plus1:) forControlEvents:UIControlEventTouchUpInside];
[self.window addSubview:a3Button];
UIButton *a4Button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
a4Button.frame = CGRectMake(40,160, 40, 40);
[a4Button setTitle:@"4" forState:UIControlStateNormal];
a4Button.backgroundColor = [UIColor blackColor];
[a4Button addTarget:self action:@selector(plus1:) forControlEvents:UIControlEventTouchUpInside];
[self.window addSubview:a4Button];
UIButton *a5Button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
a5Button.frame = CGRectMake(120, 160, 40, 40);
[a5Button setTitle:@"5" forState:UIControlStateNormal];
a5Button.backgroundColor = [UIColor blackColor];
[a5Button addTarget:self action:@selector(plus1:) forControlEvents:UIControlEventTouchUpInside];
[self.window addSubview:a5Button];
UIButton*a6Button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
a6Button.frame = CGRectMake(200, 160, 40, 40);
[a6Button setTitle:@"6" forState:UIControlStateNormal];
a6Button.backgroundColor = [UIColor blackColor];
[a6Button addTarget:self action:@selector(plus1:) forControlEvents:UIControlEventTouchUpInside];
[self.window addSubview:a6Button];
UIButton *a7Button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
a7Button.frame = CGRectMake(40,220, 40, 40);
[a7Button setTitle:@"7" forState:UIControlStateNormal];
a7Button.backgroundColor = [UIColor blackColor];
[a7Button addTarget:self action:@selector(plus1:) forControlEvents:UIControlEventTouchUpInside];
[self.window addSubview:a7Button];
UIButton *a8Button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
a8Button.frame = CGRectMake(120, 220, 40, 40);
[a8Button setTitle:@"8" forState:UIControlStateNormal];
a8Button.backgroundColor = [UIColor blackColor];
[a8Button addTarget:self action:@selector(plus1:) forControlEvents:UIControlEventTouchUpInside];
[self.window addSubview:a8Button];
UIButton * a9Button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
a9Button.frame = CGRectMake(200, 220, 40, 40);
[a9Button setTitle:@"9" forState:UIControlStateNormal];
a9Button.backgroundColor = [UIColor blackColor];
[a9Button addTarget:self action:@selector(plus1:) forControlEvents:UIControlEventTouchUpInside];
[self.window addSubview:a9Button];
UIButton *dyButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
dyButton.frame = CGRectMake(260, 100, 40, 40);
[dyButton setTitle:@"=" forState:UIControlStateNormal];
dyButton.backgroundColor = [UIColor blackColor];
[dyButton addTarget:self action:@selector(plus1:) forControlEvents:UIControlEventTouchUpInside];
[self.window addSubview:dyButton];
UIButton *sumButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
sumButton.frame = CGRectMake(260, 160, 40, 40);
[sumButton setTitle:@"+" forState:UIControlStateNormal];
sumButton.backgroundColor = [UIColor blackColor];
[sumButton addTarget:self action:@selector(plus1:) forControlEvents:UIControlEventTouchUpInside];
[self.window addSubview:sumButton];
UIButton *jfButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
jfButton.frame = CGRectMake(260, 220, 40, 40);
[jfButton setTitle:@"-" forState:UIControlStateNormal];
jfButton.backgroundColor = [UIColor blackColor];
[sumButton addTarget:self action:@selector(plus1:) forControlEvents:UIControlEventTouchUpInside];
[self.window addSubview:jfButton];
return YES;
}
- (void)plus1:(UIButton *)button
{
int sum = 0 ;
NSString *number1 =[button titleForState:UIControlStateNormal];
UILabel *lable= (UILabel *)[self.window viewWithTag:100];
int number = number1.intValue;
if (number >= 0 && number <= 9) {
lable.text = number1 ;
}
if ([number1 isEqualToString:@"+"]) {
sum += number;
}
if ([number1 isEqualToString:@"="]) {
lable.text = [NSString stringWithFormat:@"%d", sum];
}
}
0 0
- 计算器(没写完呢)
- {YiGeZiWoJianJie}个人简历(还没写完呢)
- 词典(没写完)
- 没写完
- 寻路小例子 没写完(待续)
- 栈模拟 四则运算 (没写完)
- 标题还没写完
- 时间 没写完
- compute manager(1) :init_host(self)(没写完)
- ECG曲率计算,曲线拟合(还没写完)
- 昨天大个哥来我家吃饭了,今天下午肚子剧痛,希望明天恢复,程序还没写完呢~
- 文本查询 没写完代码
- 保存一下,还没写完
- 继续没写完的章节
- java中的Singleton (单立)设计模式(还没写完)
- Oracle 日志的编写与查询的一种方法(还没写完)
- 算法导论—红黑树(还没写完,先备份一个)
- 上一篇没写完(编辑器有问题zz),继续写
- 1015. Reversible Primes
- pandas+xlrd+numpy按元素计算批量处理excel所有sheet
- 定时任务文件配置和自定义
- 【leetcode】 Fraction_to_Recurring_Decimal
- 一个做页面静态化的php类
- 计算器(没写完呢)
- oc常见数据类型
- HashSet<E>泛型类
- 查看手机本地ip地址
- LeetCode-Sort List,链表排序(插入和归并),时间复杂度O(n^2) and O(nlgn)
- Bi-shoe and Phi-shoe(欧拉函数)
- 用DOS查看手机ip地址
- 打印日志
- 人丑就要多读书