OC中使用UI自定义控件实现计算器的设计(版本1简单的加减乘除,连加,连减,连除,连乘)
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController<UIApplicationDelegate>
{
float _operator1;
float _operator2;
float _result;
}
@end
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
UITextField * textFied1 = [[UITextField alloc]initWithFrame:CGRectMake(10, 30, 300 ,50)];
textFied1.borderStyle = UITextBorderStyleLine;
textFied1.backgroundColor = [UIColor redColor];
[self.view addSubview:textFied1];
textFied1.clearButtonMode = UITextFieldViewModeAlways;
textFied1.tag = 007;
UIButton * btn1 = [UIButton buttonWithType:UIButtonTypeCustom];
btn1.Frame=CGRectMake(10, 90, 70, 70);
btn1.backgroundColor = [UIColor orangeColor];
[self.view addSubview:btn1];
[btn1 setTitle:@"7" forState:UIControlStateNormal];
[btn1 addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
btn1.tag = 7;
UIButton * btn2 = [UIButton buttonWithType:UIButtonTypeCustom];
btn2.Frame=CGRectMake(85, 90, 70, 70);
btn2.backgroundColor = [UIColor orangeColor];
[self.view addSubview:btn2];
[btn2 setTitle:@"8" forState:UIControlStateNormal];
btn2.tag = 8;
[btn2 addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
UIButton * btn3 = [UIButton buttonWithType:UIButtonTypeCustom];
btn3.Frame=CGRectMake(160, 90, 70, 70);
btn3.backgroundColor = [UIColor orangeColor];
[self.view addSubview:btn3];
[btn3 setTitle:@"9" forState:UIControlStateNormal];
btn3.tag = 9;
[btn3 addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
UIButton * btn4 = [UIButton buttonWithType:UIButtonTypeCustom];
btn4.Frame=CGRectMake(235, 90, 70, 70);
btn4.backgroundColor = [UIColor orangeColor];
[self.view addSubview:btn4];
[btn4 setTi