-
Notifications
You must be signed in to change notification settings - Fork 0
/
BMICalculatorViewController.m
151 lines (112 loc) · 3.4 KB
/
BMICalculatorViewController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
//
// BMICalculatorViewController.m
// endotools
//
// Created by Johnson Thomas on 12/29/12.
// Copyright (c) 2012 Johnson Thomas. All rights reserved.
//
#import "BMICalculatorViewController.h"
@interface BMICalculatorViewController ()
@end
@implementation BMICalculatorViewController
@synthesize Units;
@synthesize Height1;
@synthesize Height2;
@synthesize Weight;
@synthesize Bmi;
@synthesize HeightLabel1;
@synthesize HeightLabel2;
@synthesize WeightLabel;
float lb, kg, feet, inch, meter1, meter2, totalmeter, bmivalue;
NSInteger metricvalue= 0;
-(IBAction)CalculateBMI:(id)sender;{
switch (metricvalue) {
case 0:
{
feet = [Height1.text floatValue];
inch = [Height2.text floatValue];
meter1 = feet * 0.3048;
meter2 = inch * 0.0254;
totalmeter = meter1 + meter2;
lb =[Weight.text floatValue];
kg = lb / 2.2;
bmivalue = kg / (totalmeter * totalmeter);
Bmi.text = [NSString stringWithFormat:@"%.2f",bmivalue];
}
break;
case 1:
{
totalmeter = [Height1.text floatValue];
kg = [Weight.text floatValue];
bmivalue = kg / (totalmeter * totalmeter);
Bmi.text = [NSString stringWithFormat:@"%.2f",bmivalue];
//NSLog(@" Metric");
}
break;
default:
break;
}
}
-(IBAction)hidekeyboard:(id)sender;{
[sender resignFirstResponder];
}
-(IBAction)UnitsChanged:(id)sender;{
switch (self.Units.selectedSegmentIndex) {
case 0:
{
Bmi.text = @"";
HeightLabel1.text = @"Feet";
Height1.text =@"";
Height2.text =@"";
[HeightLabel1 setHidden:NO];
[Height2 setHidden:NO];
[HeightLabel2 setHidden:NO];
HeightLabel2.text = @"Inches";
WeightLabel.text = @"Pounds";
Weight.text =@"";
metricvalue=0;
}
break;
case 1:
{
Height1.text = @"";
Height2.text = @"";
Weight.text = @"";
Bmi.text = @"";
HeightLabel1.text = @"Meters";
[HeightLabel2 setHidden:YES];
[Height2 setHidden:YES];
WeightLabel.text = @"Kilogram";
metricvalue = 1;
}
break;
default:
break;
}
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
//self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:255/255 green:102/255 blue:102/255 alpha:1];
//self.navigationController.navigationBar.tintColor = [UIColor redColor];
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)keyboardisappear:(id)sender {
[Height1 resignFirstResponder];
[Height2 resignFirstResponder];
[Weight resignFirstResponder];
}
@end