您的位置:首页 > 产品设计 > UI/UE

ios计算个税方法以及ui界面设计代码详解

2015-04-09 09:12 459 查看
//

// ZYAppDelegate.m

// UITest1

//

// Created by cacahaha on 15/4/8.

// Copyright (c) 2015年 ZhiYou. All rights reserved.

//

import “ZYAppDelegate.h”

@implementation ZYAppDelegate

//入口方法

- (BOOL)application:(UIApplication )application didFinishLaunchingWithOptions:(NSDictionary )launchOptions

{

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

self.window.backgroundColor = [UIColor greenColor];

[self.window makeKeyAndVisible];

//背景button按钮,用来让鼠标点击背景时让键盘隐藏

UIButton *buttonbg = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];//创建一个button对象,并初始化其位置

[_window addSubview:buttonbg];//将button添加到窗口

[buttonbg addTarget:self action:@selector(bgclick) forControlEvents:UIControlEventTouchUpInside];//为button添加点击事件bgclick,事件类型是当手指触摸按钮离开后仍在按钮之上则会触发此事件

//工资label
UILabel *label1 = [[UILabel alloc]initWithFrame:CGRectMake(30, 100, 40, 35)];//创建一个label对象,并初始化其位置信息
[_window addSubview:label1];//将label添加到窗口
label1.textAlignment = NSTextAlignmentCenter;//设置label中文字的对齐方式
//label1.backgroundColor = [UIColor redColor];//设置label的背景色
label1.text = @"工资";//设置label中文字内容

//label 标签,创建一个label对象
label = [[UILabel alloc] init];
//设置label要显示的文字
label.text = @"我会显示税后工资吆";
//左上角是0,0 点,屏幕宽度320,高度480(3.5寸),高度568(4寸屏),x,y指的是左上角的坐标
CGRect rect = CGRectMake(60, 160, 200, 40);
label.frame = rect;
label.textAlignment = NSTextAlignmentCenter;
UIColor *color2 = [[UIColor alloc] initWithRed:0 green:1 blue:0 alpha:1];//创建一个color对象
label.textColor = color2;//设置label字体颜色
UIFont *size = [UIFont fontWithName:@"TrebuchetMS-Bold" size:20];//创建一个字体对象
label.font = size;//设置label字体大小
//颜色的范围是[0,1]
//alpha 透明度,为1代表全不透明,0 全透明
UIColor *color = [[UIColor alloc] initWithRed:154 / 255.0 green:58 / 255.0 blue:60.0 / 255 alpha:1];//创建一个color对象
label.backgroundColor = color;//设置label背景色
//add 添加  sub 子 view 视图(控件)
[_window addSubview:label];


// UILabel *label2 = [[UILabel alloc] init];

// label2.text = @”姓名:”;

// label2.frame = CGRectMake(0, 0, 100, 40);

// [_window addSubview:label2];

textField = [[UITextField alloc]init];//创建textField对象

textField.frame = CGRectMake(70, 100, 200, 35);//设置textField位置信息

textField.borderStyle = UITextBorderStyleRoundedRect;//设置textField的边框样式

textField.placeholder = @”请输入你的工资”;//设置textField的默认提示文字内容

textField.keyboardType = UIKeyboardTypeNumberPad;//设置textField获得焦点时候显示键盘的类型,此处默认是的纯数字键盘

[textField becomeFirstResponder];//设置textField初始状态,此处默认使textField获得焦点,即自动显示数字键盘

[_window addSubview:textField];//把textField添加到窗口

//计算工资按钮
UIButton *button = [[UIButton alloc] init];//创建按钮对象
button.backgroundColor = [UIColor grayColor];//设置按钮背景色
[button addTarget:self action:@selector(buttomOnclick) forControlEvents:UIControlEventTouchUpInside];//给button按钮添加buttonOnclick时间,事件类型是当手指触摸按钮离开后仍在按钮之上则会触发此事件
button.frame = CGRectMake(110, 220, 100, 35);//设置button的位置
[button setTitle:@"计算工资" forState:UIControlStateNormal];//设置button上边文字内容,以及默认的控制状态
[_window addSubview:button];//添加button按钮到窗口
return YES;


}

//计算按钮的点击事件

-(void)buttomOnclick

{

NSString *con = textField.text;//获取textField中输入的内容,并用字符串con接收

float salary = [con floatValue];//用字符串类中的floatValue方法将其转换成浮点型

float a = [self tax:salary];//调用计算个税的方法tax来将工资计算出来并赋值给a

NSString *sa = [NSString stringWithFormat:@”%f”,a];//将a转换成字符串类型

label.text = sa;//将sa赋值给label标签

}

//隐藏键盘方法

- (void)bgclick

{

[textField resignFirstResponder];//点击事件,是textField的键盘隐藏

}

//计算个税方法

- (float)tax:(float)aSalary

{

// float standerMoney;//基准工资

// float threeMoney;//三险一金

// float pernalMoney;//以纳所得额

// float mustMoney;//个税

// float shuiLv;//税率

// float suSuanKouChouShu;//速算扣除数

//

//

// if (aSalary > 7662)

// {

// standerMoney = 7662;

// }

// else

// {

// standerMoney = aSalary;

// }

//

// threeMoney = standerMoney * (8.0/100 + 2.0/100 + 0.5/100 + 12.0/100);

// pernalMoney = aSalary - threeMoney- 3500;

//

//

//

//

//

// if (pernalMoney > 0)

// {

// if (pernalMoney <= 1500)

// {

// shuiLv = 3.0/100;

// suSuanKouChouShu = 0;

// }

// else if (pernalMoney > 1500 && pernalMoney <= 4500)

// {

// shuiLv = 10.0/100;

// suSuanKouChouShu = 105;

// }

// else if (pernalMoney > 4500 && pernalMoney <= 9000)

// {

// shuiLv = 20.0/100;

// suSuanKouChouShu = 555;

// }

// else if (pernalMoney > 9000 && pernalMoney <= 35000)

// {

// shuiLv = 25.0/100;

// suSuanKouChouShu = 1005;

// }

// else if (pernalMoney > 35000 && pernalMoney <= 55000)

// {

// shuiLv = 30.0/100;

// suSuanKouChouShu = 2755;

// }

// else if (pernalMoney > 55000 && pernalMoney <= 80000)

// {

// shuiLv = 35.0/100;

// suSuanKouChouShu = 5505;

// }

// else

// {

// shuiLv = 45.0/100;

// suSuanKouChouShu = 13505 ;

// }

//

// mustMoney = pernalMoney * shuiLv - suSuanKouChouShu;

// return mustMoney;

// }

// else

// {

// return 0;

// }

float baseMoney;//基准工资

float threeMoney;//三险一金

float pernalMoney;//已纳税所得额

float mustMoney;//个税

float shuiLv;//税率

float kouShui;//扣税

if (aSalary > 7662) {

baseMoney = 7662;

}

else

{

baseMoney = aSalary;

}

threeMoney = baseMoney * ( 8.0 / 100 + 2.0 / 100 +0.5 / 100 +12.0 / 100) + 3;

pernalMoney = aSalary - threeMoney - 3500;

if (pernalMoney > 0) {

if (pernalMoney <=1500) {

shuiLv = 3.0/100;

kouShui = 0;

}

else if (pernalMoney > 1500 && pernalMoney <= 4500) {
shuiLv = 10.0/100;
kouShui = 105;
}

else if (pernalMoney > 4500 && pernalMoney <= 9000) {
shuiLv = 20.0/100;
kouShui = 555;
}

else if (pernalMoney > 9000 && pernalMoney <= 35000) {
shuiLv = 25.0/100;
kouShui = 1005;
}

else if (pernalMoney > 35000 && pernalMoney <= 55000) {
shuiLv = 30.0/100;
kouShui = 2775;
}

else if (pernalMoney > 55000 && pernalMoney <= 80000) {
shuiLv = 35.0/100;
kouShui = 5505;
}
else
{
shuiLv = 45.0/100;
kouShui = 13505;
}
mustMoney = pernalMoney * shuiLv - kouShui;
return mustMoney;
}
else
{
return 0;
}


}

- (void)applicationWillResignActive:(UIApplication *)application

{

// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.

// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.

}

(void)applicationDidEnterBackground:(UIApplication *)application

{

// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.

// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.

}

(void)applicationWillEnterForeground:(UIApplication *)application

{

// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.

}

(void)applicationDidBecomeActive:(UIApplication *)application

{

// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.

}

(void)applicationWillTerminate:(UIApplication *)application

{

// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.

}

@end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐