学习练习--UI界面实现个人所得税计算
来源:互联网 发布:阿里云的解决方案ppt 编辑:程序博客网 时间:2024/05/24 05:43
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindowalloc] initWithFrame:[[UIScreenmainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColorwhiteColor];
[self.windowmakeKeyAndVisible];
UILabel *welcomLb = [[UILabelalloc]initWithFrame:CGRectMake(80,20, 160,50)];
welcomLb.text =@"个人所得税计算";
welcomLb.textColor = [UIColorgreenColor];
welcomLb.font =[UIFontboldSystemFontOfSize:22];
welcomLb.shadowColor = [UIColorpurpleColor];
welcomLb.shadowOffset =CGSizeMake(2,2);
welcomLb.textAlignment =NSTextAlignmentCenter;
[self.windowaddSubview:welcomLb];
//输入工资
UILabel *salaryLb = [[UILabelalloc]initWithFrame:CGRectMake(50,70, 80,40)];
salaryLb.text =@"工资:";
salaryLb.textAlignment =NSTextAlignmentLeft;
[self.windowaddSubview:salaryLb];
salaryTF = [[UITextFieldalloc]initWithFrame:CGRectMake(150,70, 140,40)];
salaryTF.borderStyle =UITextBorderStyleRoundedRect;
salaryTF.placeholder =@"请输入.......";
salaryTF.keyboardType =UIKeyboardTypeNumberPad;
[self.windowaddSubview:salaryTF];
//个人所得税
UILabel *taxOutLb = [[UILabelalloc]initWithFrame:CGRectMake(50,110, 80,40)];
taxOutLb.textAlignment =NSTextAlignmentLeft;
taxOutLb.text =@"应缴税:";
[self.windowaddSubview:taxOutLb];
taxOutTF = [[UITextFieldalloc]initWithFrame:CGRectMake(150,110, 140,40)];
taxOutTF.userInteractionEnabled =NO;
taxOutTF.borderStyle =UITextBorderStyleRoundedRect;
taxOutTF.placeholder =@"应缴税......";
[self.windowaddSubview:taxOutTF];
//实际工资
UILabel *factSalaryLb = [[UILabelalloc]initWithFrame:CGRectMake(50,150, 80,40)];
factSalaryLb.text =@"真工资:";
factSalaryLb.textAlignment =NSTextAlignmentLeft;
[self.windowaddSubview:factSalaryLb];
factSalaryTF = [[UITextFieldalloc]initWithFrame:CGRectMake(150,150, 140,40)];
factSalaryTF.userInteractionEnabled =NO;
factSalaryTF.borderStyle =UITextBorderStyleRoundedRect;
factSalaryTF.placeholder =@"实际工资是......";
[self.windowaddSubview:factSalaryTF];
//两个按钮
UIButton * calculateBtn = [UIButtonbuttonWithType:UIButtonTypeSystem];
calculateBtn.frame =CGRectMake(60,220, 80,40);
[calculateBtn setTitle:@"计算"forState:UIControlStateNormal];
calculateBtn.backgroundColor = [UIColorgroupTableViewBackgroundColor];
[calculateBtn setTitleColor:[UIColorgrayColor]forState:UIControlStateNormal];
[calculateBtn addTarget:selfaction:@selector(calculateTax)forControlEvents:UIControlEventTouchUpInside];
[self.windowaddSubview:calculateBtn];
UIButton * taxOutBtn = [UIButtonbuttonWithType:UIButtonTypeSystem];
taxOutBtn.backgroundColor = [UIColorgroupTableViewBackgroundColor];
taxOutBtn.frame =CGRectMake(180,220, 80,40);
[taxOutBtn setTitle:@"重置"forState:UIControlStateNormal];
[taxOutBtn setTitleColor:[UIColorgrayColor]forState:UIControlStateNormal];
[taxOutBtn addTarget:selfaction:@selector(resetAll)forControlEvents:UIControlEventTouchUpInside];
[self.windowaddSubview:taxOutBtn];
returnYES;
}
-(void)calculateTax{
float salary = [[salaryTFtext]floatValue];
if (salary !=0) {
float exSalary;
float a,b,factSalary;
if (salary <7662) {
exSalary = salary * ( 1 - (0.08 +0.02 + 0.005 +0.12));
}else{
exSalary = salary - (7662 *(0.08 +0.02 + 0.005 +0.12));
}
exSalary -= 3500;
if (exSalary <=0) {
a = 0; b =0;
}elseif(exSalary <= 1500){
a = exSalary * 0.03;
b = 0;
}elseif (exSalary <= 4500){
a = exSalary * 0.1;
b = 105;
}elseif (exSalary <= 9000){
a = exSalary * 0.2;
b = 555;
}elseif (exSalary <= 35000){
a = exSalary * 0.25;
b = 1005;
}elseif(exSalary <= 55000){
a = exSalary * 0.3;
b = 2755;
}elseif (exSalary <= 80000){
a= exSalary * 0.35;
b = 5505;
}else{
a = exSalary * 0.45;
b = 13505;
}
factSalary = exSalary + 3500 -(a - b);
taxOutTF.text = [NSStringstringWithFormat:@"%f",a - b];
factSalaryTF.text = [NSStringstringWithFormat:@"%f",factSalary];
}
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
[salaryTFendEditing:NO];
[taxOutTFendEditing:NO];
[factSalaryTFendEditing:NO];
}
@end
实现了个人所得税和实际工资的计算
得到UITextField新用法
UITextField *tf = [[UITextField alloc]initWithFrame:CGRect(100,100,100,100)];
tf.userInteractionEnable = NO;//UITextField是否能读写
tf.keyboardType = UIKeyboardTypeNumberPad;//UITextField所触发的键盘类型
[self.window addSubview];
float a = [[tf text]floatValue];//获取tf中的float值
//重写系统方法,使键盘落下
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
[tf endEditing:NO];
}
复习:
UIView 和 UIButton小运用:view1-->view2 view1-->view3
//简单qq登录、注册页面(功能未实现,仅用于UIView之间跳转)
@implementation LHAppDelegate
-(void)logo{
view1 = [[UIViewalloc]initWithFrame:CGRectMake(0,0, 320,480)];
[self.windowaddSubview:view1];
//背景图
UIImageView *bgIV1 = [[UIImageViewalloc] initWithFrame:CGRectMake(0,0,320,480)];
bgIV1.image = [UIImageimageNamed:@"1.jpg"];
[view1addSubview:bgIV1];
//欢迎行
UILabel *welcomeLb = [[UILabelalloc] initWithFrame:CGRectMake(65,100,190,40)];
welcomeLb.text =@"QQ,丰富你的生活";
welcomeLb.textColor =[UIColorblueColor];
welcomeLb.font = [UIFontsystemFontOfSize:20];
[view1addSubview:welcomeLb];
//账号行
UILabel *unameLb = [[UILabelalloc] initWithFrame:CGRectMake(50,150,50,40)];
UITextField *unameTf = [[UITextFieldalloc] initWithFrame:CGRectMake(120,150,150,40)];
unameLb.text =@"QQ号:";
unameLb.font = [UIFontsystemFontOfSize:14];
unameTf.placeholder =@"请输入QQ号......";
[view1addSubview:unameTf];
unameTf.borderStyle =3;
[view1addSubview:unameLb];
//密码行
UILabel *upwdLb = [[UILabelalloc] initWithFrame:CGRectMake(50,210,50,30)];
UITextField *upwdTf = [[UITextFieldalloc] initWithFrame:CGRectMake(120,210,150,30)];
upwdLb.text =@"密码:";
upwdLb.font = [UIFontsystemFontOfSize:14];
upwdTf.placeholder =@"请输入密码......";
[view1addSubview:upwdTf];
upwdTf.borderStyle =3;
[view1addSubview:upwdLb];
//登陆和注册行
UIButton *loginBtn = [UIButtonbuttonWithType:UIButtonTypeSystem];
loginBtn.frame =CGRectMake(115,260, 50,30);
UIButton *regBtn = [UIButtonbuttonWithType:UIButtonTypeSystem];
regBtn.frame =CGRectMake(205,260, 50,30);
loginBtn.backgroundColor = [UIColorblueColor];
regBtn.backgroundColor = [UIColorblueColor];
[view1addSubview:loginBtn];
[view1addSubview:regBtn];
[loginBtn setTitle:@"登陆"forState:UIControlStateNormal];
[regBtn setTitle:@"注册"forState:UIControlStateNormal];
[loginBtn setTitleColor:[UIColorblackColor] forState:UIControlStateNormal];
[regBtn setTitleColor:[UIColorblackColor] forState:UIControlStateNormal];
[loginBtn addTarget:nilaction:@selector(login)forControlEvents:UIControlEventTouchUpInside];
[regBtn addTarget:nilaction:@selector(reg)forControlEvents:UIControlEventTouchUpInside];
}
-(void)reg{
[UIViewbeginAnimations:nilcontext:nil];
[UIViewsetAnimationDuration:1];
[UIViewsetAnimationDelegate:self];
[UIViewsetAnimationTransition:UIViewAnimationTransitionCurlDownforView:self.windowcache:YES];
[UIViewcommitAnimations];
view2 = [[UIViewalloc]initWithFrame:CGRectMake(0,0, 320,480)];
[self.windowaddSubview:view2];
UIImageView *bgIV2 = [[UIImageViewalloc]initWithFrame:CGRectMake(0,0, 320,480)];
bgIV2.image = [UIImageimageNamed:@"2.jpg"];
[view2addSubview:bgIV2];
}
-(void)login{
[UIViewbeginAnimations:nilcontext:nil];
[UIViewsetAnimationDuration:1];
[UIViewsetAnimationDelegate:self];
[UIViewsetAnimationTransition:UIViewAnimationTransitionCurlDownforView:self.windowcache:YES];
[UIViewcommitAnimations];
view3 = [[UIViewalloc]initWithFrame:CGRectMake(0,0, 320,320)];
[self.windowaddSubview:view3];
UIImageView *bgIV3 = [[UIImageViewalloc]initWithFrame:CGRectMake(0,0, 320,480)];
bgIV3.image = [UIImageimageNamed:@"3.jpg"];
[view3addSubview:bgIV3];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindowalloc] initWithFrame:[[UIScreenmainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColorwhiteColor];
[self.windowmakeKeyAndVisible];
[selflogo];
returnYES;
}
- 学习练习--UI界面实现个人所得税计算
- 练习,计算个人所得税
- java实现个人所得税计算
- C语言实现个人所得税计算
- 利用规则引擎计算个人所得税学习
- 个人所得税计算
- 个人所得税计算
- 计算个人所得税
- 个人所得税计算
- 计算个人所得税
- 个人所得税计算
- 个人所得税计算
- 个人所得税计算
- 计算个人所得税
- 个人所得税计算
- 计算计算个人所得税2010
- UI小练习,模仿登陆界面
- 算法练习-个人所得税
- cocos2dx Sprite触摸监听
- Apache 本地配置
- 项目实践之json字符串
- Eclipse: Problem: Unable to locate the Javac Compiler in...
- 打开POWER_SAVING与串口同时使用时的冲突解决
- 学习练习--UI界面实现个人所得税计算
- hdu 4658 Integer Partition
- django数据库错误相关问题
- HM测试数据处理遇到的问题
- HDOJ 奇数阶魔方 1998
- 跟周鸿祎学互联网思维 ——《周鸿祎自述|我的互联网方法论》读后感
- CSS3属性笔记(六)
- 杭电acm第1008Elevator(电梯)
- Nim博弈与SG函数