学习练习--UI界面实现个人所得税计算
2015-05-14 22:18
501 查看
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary
*)launchOptions
{
self.window = [[UIWindow
alloc] initWithFrame:[[UIScreen
mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor
whiteColor];
[self.window
makeKeyAndVisible];
UILabel *welcomLb = [[UILabel
alloc]initWithFrame:CGRectMake(80,
20, 160,
50)];
welcomLb.text =
@"个人所得税计算";
welcomLb.textColor = [UIColor
greenColor];
welcomLb.font =[UIFont
boldSystemFontOfSize:22];
welcomLb.shadowColor = [UIColor
purpleColor];
welcomLb.shadowOffset =
CGSizeMake(2,
2);
welcomLb.textAlignment =
NSTextAlignmentCenter;
[self.window
addSubview:welcomLb];
//输入工资
UILabel *salaryLb = [[UILabel
alloc]initWithFrame:CGRectMake(50,
70, 80,
40)];
salaryLb.text =
@"工资:";
salaryLb.textAlignment =
NSTextAlignmentLeft;
[self.window
addSubview:salaryLb];
salaryTF = [[UITextField
alloc]initWithFrame:CGRectMake(150,
70, 140,
40)];
salaryTF.borderStyle =
UITextBorderStyleRoundedRect;
salaryTF.placeholder =
@"请输入.......";
salaryTF.keyboardType =
UIKeyboardTypeNumberPad;
[self.window
addSubview:salaryTF];
//个人所得税
UILabel *taxOutLb = [[UILabel
alloc]initWithFrame:CGRectMake(50,
110, 80,
40)];
taxOutLb.textAlignment =
NSTextAlignmentLeft;
taxOutLb.text =
@"应缴税:";
[self.window
addSubview:taxOutLb];
taxOutTF = [[UITextField
alloc]initWithFrame:CGRectMake(150,
110, 140,
40)];
taxOutTF.userInteractionEnabled =
NO;
taxOutTF.borderStyle =
UITextBorderStyleRoundedRect;
taxOutTF.placeholder =
@"应缴税......";
[self.window
addSubview:taxOutTF];
//实际工资
UILabel *factSalaryLb = [[UILabel
alloc]initWithFrame:CGRectMake(50,
150, 80,
40)];
factSalaryLb.text =
@"真工资:";
factSalaryLb.textAlignment =
NSTextAlignmentLeft;
[self.window
addSubview:factSalaryLb];
factSalaryTF = [[UITextField
alloc]initWithFrame:CGRectMake(150,
150, 140,
40)];
factSalaryTF.userInteractionEnabled =
NO;
factSalaryTF.borderStyle =
UITextBorderStyleRoundedRect;
factSalaryTF.placeholder =
@"实际工资是......";
[self.window
addSubview:factSalaryTF];
//两个按钮
UIButton * calculateBtn = [UIButton
buttonWithType:UIButtonTypeSystem];
calculateBtn.frame =
CGRectMake(60,
220, 80,
40);
[calculateBtn setTitle:@"计算"
forState:UIControlStateNormal];
calculateBtn.backgroundColor = [UIColor
groupTableViewBackgroundColor];
[calculateBtn setTitleColor:[UIColor
grayColor]forState:UIControlStateNormal];
[calculateBtn addTarget:self
action:@selector(calculateTax)
forControlEvents:UIControlEventTouchUpInside];
[self.window
addSubview:calculateBtn];
UIButton * taxOutBtn = [UIButton
buttonWithType:UIButtonTypeSystem];
taxOutBtn.backgroundColor = [UIColor
groupTableViewBackgroundColor];
taxOutBtn.frame =
CGRectMake(180,
220, 80,
40);
[taxOutBtn setTitle:@"重置"
forState:UIControlStateNormal];
[taxOutBtn setTitleColor:[UIColor
grayColor]forState:UIControlStateNormal];
[taxOutBtn addTarget:self
action:@selector(resetAll)
forControlEvents:UIControlEventTouchUpInside];
[self.window
addSubview:taxOutBtn];
return
YES;
}
-(void)calculateTax{
float salary = [[salaryTF
text]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;
}else
if(exSalary <= 1500){
a = exSalary * 0.03;
b = 0;
}else
if (exSalary <= 4500){
a = exSalary * 0.1;
b = 105;
}else
if (exSalary <= 9000){
a = exSalary * 0.2;
b = 555;
}else
if (exSalary <= 35000){
a = exSalary * 0.25;
b = 1005;
}else
if(exSalary <= 55000){
a = exSalary * 0.3;
b = 2755;
}else
if (exSalary <= 80000){
a= exSalary * 0.35;
b = 5505;
}else{
a = exSalary * 0.45;
b = 13505;
}
factSalary = exSalary + 3500 -(a - b);
taxOutTF.text = [NSString
stringWithFormat:@"%f",a - b];
factSalaryTF.text = [NSString
stringWithFormat:@"%f",factSalary];
}
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
[salaryTF
endEditing:NO];
[taxOutTF
endEditing:NO];
[factSalaryTF
endEditing: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 = [[UIView
alloc]initWithFrame:CGRectMake(0,
0, 320,
480)];
[self.window
addSubview:view1];
//背景图
UIImageView *bgIV1 = [[UIImageView
alloc] initWithFrame:CGRectMake(0,0,320,480)];
bgIV1.image = [UIImage
imageNamed:@"1.jpg"];
[view1
addSubview:bgIV1];
//欢迎行
UILabel *welcomeLb = [[UILabel
alloc] initWithFrame:CGRectMake(65,100,190,40)];
welcomeLb.text =
@"QQ,丰富你的生活";
welcomeLb.textColor =[UIColor
blueColor];
welcomeLb.font = [UIFont
systemFontOfSize:20];
[view1
addSubview:welcomeLb];
//账号行
UILabel *unameLb = [[UILabel
alloc] initWithFrame:CGRectMake(50,150,50,40)];
UITextField *unameTf = [[UITextField
alloc] initWithFrame:CGRectMake(120,150,150,40)];
unameLb.text =
@"QQ号:";
unameLb.font = [UIFont
systemFontOfSize:14];
unameTf.placeholder =@"请输入QQ号......";
[view1
addSubview:unameTf];
unameTf.borderStyle =
3;
[view1
addSubview:unameLb];
//密码行
UILabel *upwdLb = [[UILabel
alloc] initWithFrame:CGRectMake(50,210,50,30)];
UITextField *upwdTf = [[UITextField
alloc] initWithFrame:CGRectMake(120,210,150,30)];
upwdLb.text =
@"密码:";
upwdLb.font = [UIFont
systemFontOfSize:14];
upwdTf.placeholder =
@"请输入密码......";
[view1
addSubview:upwdTf];
upwdTf.borderStyle =
3;
[view1
addSubview:upwdLb];
//登陆和注册行
UIButton *loginBtn = [UIButton
buttonWithType:UIButtonTypeSystem];
loginBtn.frame =
CGRectMake(115,
260, 50,
30);
UIButton *regBtn = [UIButton
buttonWithType:UIButtonTypeSystem];
regBtn.frame =
CGRectMake(205,
260, 50,
30);
loginBtn.backgroundColor = [UIColor
blueColor];
regBtn.backgroundColor = [UIColor
blueColor];
[view1
addSubview:loginBtn];
[view1
addSubview:regBtn];
[loginBtn setTitle:@"登陆"
forState:UIControlStateNormal];
[regBtn setTitle:@"注册"
forState:UIControlStateNormal];
[loginBtn setTitleColor:[UIColor
blackColor] forState:UIControlStateNormal];
[regBtn setTitleColor:[UIColor
blackColor] forState:UIControlStateNormal];
[loginBtn addTarget:nil
action:@selector(login)
forControlEvents:UIControlEventTouchUpInside];
[regBtn addTarget:nil
action:@selector(reg)
forControlEvents:UIControlEventTouchUpInside];
}
-(void)reg{
[UIView
beginAnimations:nil
context:nil];
[UIView
setAnimationDuration:1];
[UIView
setAnimationDelegate:self];
[UIView
setAnimationTransition:UIViewAnimationTransitionCurlDown
forView:self.window
cache:YES];
[UIView
commitAnimations];
view2 = [[UIView
alloc]initWithFrame:CGRectMake(0,
0, 320,
480)];
[self.window
addSubview:view2];
UIImageView *bgIV2 = [[UIImageView
alloc]initWithFrame:CGRectMake(0,
0, 320,
480)];
bgIV2.image = [UIImage
imageNamed:@"2.jpg"];
[view2
addSubview:bgIV2];
}
-(void)login{
[UIView
beginAnimations:nil
context:nil];
[UIView
setAnimationDuration:1];
[UIView
setAnimationDelegate:self];
[UIView
setAnimationTransition:UIViewAnimationTransitionCurlDown
forView:self.window
cache:YES];
[UIView
commitAnimations];
view3 = [[UIView
alloc]initWithFrame:CGRectMake(0,
0, 320,
320)];
[self.window
addSubview:view3];
UIImageView *bgIV3 = [[UIImageView
alloc]initWithFrame:CGRectMake(0,
0, 320,
480)];
bgIV3.image = [UIImage
imageNamed:@"3.jpg"];
[view3
addSubview:bgIV3];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary
*)launchOptions
{
self.window = [[UIWindow
alloc] initWithFrame:[[UIScreen
mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor
whiteColor];
[self.window
makeKeyAndVisible];
[self
logo];
return
YES;
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary
*)launchOptions
{
self.window = [[UIWindow
alloc] initWithFrame:[[UIScreen
mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor
whiteColor];
[self.window
makeKeyAndVisible];
UILabel *welcomLb = [[UILabel
alloc]initWithFrame:CGRectMake(80,
20, 160,
50)];
welcomLb.text =
@"个人所得税计算";
welcomLb.textColor = [UIColor
greenColor];
welcomLb.font =[UIFont
boldSystemFontOfSize:22];
welcomLb.shadowColor = [UIColor
purpleColor];
welcomLb.shadowOffset =
CGSizeMake(2,
2);
welcomLb.textAlignment =
NSTextAlignmentCenter;
[self.window
addSubview:welcomLb];
//输入工资
UILabel *salaryLb = [[UILabel
alloc]initWithFrame:CGRectMake(50,
70, 80,
40)];
salaryLb.text =
@"工资:";
salaryLb.textAlignment =
NSTextAlignmentLeft;
[self.window
addSubview:salaryLb];
salaryTF = [[UITextField
alloc]initWithFrame:CGRectMake(150,
70, 140,
40)];
salaryTF.borderStyle =
UITextBorderStyleRoundedRect;
salaryTF.placeholder =
@"请输入.......";
salaryTF.keyboardType =
UIKeyboardTypeNumberPad;
[self.window
addSubview:salaryTF];
//个人所得税
UILabel *taxOutLb = [[UILabel
alloc]initWithFrame:CGRectMake(50,
110, 80,
40)];
taxOutLb.textAlignment =
NSTextAlignmentLeft;
taxOutLb.text =
@"应缴税:";
[self.window
addSubview:taxOutLb];
taxOutTF = [[UITextField
alloc]initWithFrame:CGRectMake(150,
110, 140,
40)];
taxOutTF.userInteractionEnabled =
NO;
taxOutTF.borderStyle =
UITextBorderStyleRoundedRect;
taxOutTF.placeholder =
@"应缴税......";
[self.window
addSubview:taxOutTF];
//实际工资
UILabel *factSalaryLb = [[UILabel
alloc]initWithFrame:CGRectMake(50,
150, 80,
40)];
factSalaryLb.text =
@"真工资:";
factSalaryLb.textAlignment =
NSTextAlignmentLeft;
[self.window
addSubview:factSalaryLb];
factSalaryTF = [[UITextField
alloc]initWithFrame:CGRectMake(150,
150, 140,
40)];
factSalaryTF.userInteractionEnabled =
NO;
factSalaryTF.borderStyle =
UITextBorderStyleRoundedRect;
factSalaryTF.placeholder =
@"实际工资是......";
[self.window
addSubview:factSalaryTF];
//两个按钮
UIButton * calculateBtn = [UIButton
buttonWithType:UIButtonTypeSystem];
calculateBtn.frame =
CGRectMake(60,
220, 80,
40);
[calculateBtn setTitle:@"计算"
forState:UIControlStateNormal];
calculateBtn.backgroundColor = [UIColor
groupTableViewBackgroundColor];
[calculateBtn setTitleColor:[UIColor
grayColor]forState:UIControlStateNormal];
[calculateBtn addTarget:self
action:@selector(calculateTax)
forControlEvents:UIControlEventTouchUpInside];
[self.window
addSubview:calculateBtn];
UIButton * taxOutBtn = [UIButton
buttonWithType:UIButtonTypeSystem];
taxOutBtn.backgroundColor = [UIColor
groupTableViewBackgroundColor];
taxOutBtn.frame =
CGRectMake(180,
220, 80,
40);
[taxOutBtn setTitle:@"重置"
forState:UIControlStateNormal];
[taxOutBtn setTitleColor:[UIColor
grayColor]forState:UIControlStateNormal];
[taxOutBtn addTarget:self
action:@selector(resetAll)
forControlEvents:UIControlEventTouchUpInside];
[self.window
addSubview:taxOutBtn];
return
YES;
}
-(void)calculateTax{
float salary = [[salaryTF
text]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;
}else
if(exSalary <= 1500){
a = exSalary * 0.03;
b = 0;
}else
if (exSalary <= 4500){
a = exSalary * 0.1;
b = 105;
}else
if (exSalary <= 9000){
a = exSalary * 0.2;
b = 555;
}else
if (exSalary <= 35000){
a = exSalary * 0.25;
b = 1005;
}else
if(exSalary <= 55000){
a = exSalary * 0.3;
b = 2755;
}else
if (exSalary <= 80000){
a= exSalary * 0.35;
b = 5505;
}else{
a = exSalary * 0.45;
b = 13505;
}
factSalary = exSalary + 3500 -(a - b);
taxOutTF.text = [NSString
stringWithFormat:@"%f",a - b];
factSalaryTF.text = [NSString
stringWithFormat:@"%f",factSalary];
}
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
[salaryTF
endEditing:NO];
[taxOutTF
endEditing:NO];
[factSalaryTF
endEditing: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 = [[UIView
alloc]initWithFrame:CGRectMake(0,
0, 320,
480)];
[self.window
addSubview:view1];
//背景图
UIImageView *bgIV1 = [[UIImageView
alloc] initWithFrame:CGRectMake(0,0,320,480)];
bgIV1.image = [UIImage
imageNamed:@"1.jpg"];
[view1
addSubview:bgIV1];
//欢迎行
UILabel *welcomeLb = [[UILabel
alloc] initWithFrame:CGRectMake(65,100,190,40)];
welcomeLb.text =
@"QQ,丰富你的生活";
welcomeLb.textColor =[UIColor
blueColor];
welcomeLb.font = [UIFont
systemFontOfSize:20];
[view1
addSubview:welcomeLb];
//账号行
UILabel *unameLb = [[UILabel
alloc] initWithFrame:CGRectMake(50,150,50,40)];
UITextField *unameTf = [[UITextField
alloc] initWithFrame:CGRectMake(120,150,150,40)];
unameLb.text =
@"QQ号:";
unameLb.font = [UIFont
systemFontOfSize:14];
unameTf.placeholder =@"请输入QQ号......";
[view1
addSubview:unameTf];
unameTf.borderStyle =
3;
[view1
addSubview:unameLb];
//密码行
UILabel *upwdLb = [[UILabel
alloc] initWithFrame:CGRectMake(50,210,50,30)];
UITextField *upwdTf = [[UITextField
alloc] initWithFrame:CGRectMake(120,210,150,30)];
upwdLb.text =
@"密码:";
upwdLb.font = [UIFont
systemFontOfSize:14];
upwdTf.placeholder =
@"请输入密码......";
[view1
addSubview:upwdTf];
upwdTf.borderStyle =
3;
[view1
addSubview:upwdLb];
//登陆和注册行
UIButton *loginBtn = [UIButton
buttonWithType:UIButtonTypeSystem];
loginBtn.frame =
CGRectMake(115,
260, 50,
30);
UIButton *regBtn = [UIButton
buttonWithType:UIButtonTypeSystem];
regBtn.frame =
CGRectMake(205,
260, 50,
30);
loginBtn.backgroundColor = [UIColor
blueColor];
regBtn.backgroundColor = [UIColor
blueColor];
[view1
addSubview:loginBtn];
[view1
addSubview:regBtn];
[loginBtn setTitle:@"登陆"
forState:UIControlStateNormal];
[regBtn setTitle:@"注册"
forState:UIControlStateNormal];
[loginBtn setTitleColor:[UIColor
blackColor] forState:UIControlStateNormal];
[regBtn setTitleColor:[UIColor
blackColor] forState:UIControlStateNormal];
[loginBtn addTarget:nil
action:@selector(login)
forControlEvents:UIControlEventTouchUpInside];
[regBtn addTarget:nil
action:@selector(reg)
forControlEvents:UIControlEventTouchUpInside];
}
-(void)reg{
[UIView
beginAnimations:nil
context:nil];
[UIView
setAnimationDuration:1];
[UIView
setAnimationDelegate:self];
[UIView
setAnimationTransition:UIViewAnimationTransitionCurlDown
forView:self.window
cache:YES];
[UIView
commitAnimations];
view2 = [[UIView
alloc]initWithFrame:CGRectMake(0,
0, 320,
480)];
[self.window
addSubview:view2];
UIImageView *bgIV2 = [[UIImageView
alloc]initWithFrame:CGRectMake(0,
0, 320,
480)];
bgIV2.image = [UIImage
imageNamed:@"2.jpg"];
[view2
addSubview:bgIV2];
}
-(void)login{
[UIView
beginAnimations:nil
context:nil];
[UIView
setAnimationDuration:1];
[UIView
setAnimationDelegate:self];
[UIView
setAnimationTransition:UIViewAnimationTransitionCurlDown
forView:self.window
cache:YES];
[UIView
commitAnimations];
view3 = [[UIView
alloc]initWithFrame:CGRectMake(0,
0, 320,
320)];
[self.window
addSubview:view3];
UIImageView *bgIV3 = [[UIImageView
alloc]initWithFrame:CGRectMake(0,
0, 320,
480)];
bgIV3.image = [UIImage
imageNamed:@"3.jpg"];
[view3
addSubview:bgIV3];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary
*)launchOptions
{
self.window = [[UIWindow
alloc] initWithFrame:[[UIScreen
mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor
whiteColor];
[self.window
makeKeyAndVisible];
[self
logo];
return
YES;
}
相关文章推荐
- Javascript实现计算个人所得税
- 利用规则引擎计算个人所得税学习
- 利用规则引擎计算个人所得税学习
- 利用规则引擎计算个人所得税学习
- 利用规则引擎计算个人所得税学习
- 练习,计算个人所得税
- Javascript实现计算个人所得税
- java实现个人所得税计算
- activiti学习--12 个人任务及三种分配方式:直接设置代理人+流程变量设置代理人+实现类的方式设置代理人+将任务代理人设置为别人
- 装饰器应用,Python模块学习之(__call__)实现准确计算函数运行时间
- 从零开始python小案例003计算北京市个人所得税
- 关于于渊的一个操作系统的实现第二版学习之第二章bochs裸机启动的练习
- 关于于渊的一个操作系统的实现第二版学习之第三章bochs裸机启动的练习3.1
- 4-4 计算个人所得税
- SSH与SSM学习之SSH实现CRM练习01——客户列表01_客户列表分析
- SSH与SSM学习之SSH实现CRM练习02——客户列表02_PageBean
- SSH与SSM学习之SSH实现CRM练习03——客户列表03_CustomerDao
- SSH与SSM学习之SSH实现CRM练习04——客户列表04_CustomerService
- SSH与SSM学习之SSH实现CRM练习05——客户列表05_CustomerAction
- SSH与SSM学习之SSH实现CRM练习06——客户列表06_页面和测试