-(Ibaction) Calaction: (UIButton *) Sender {
Self.number1 = [Self.resultLabel.textfloatValue];
Self.operator = Sender.tag;
Self.resultLabel.text = @ "0";
}
-(Ibaction) clear: (ID) Sender {
Self.resultLabel.text = @ "0";
Self.resultLabel.font = [Uifont fontwithname:@ "Zapfino" size:70];
Self.resultLabel.font = [uifontsystemfontofsize:70];
}
-(Ibaction) Resultaction: (ID) Sender {
float number2 = [Self.resultLabel.text floatvalue];
float result = 0;
Switch (self.operator) {
Case 0://+
result = Self.number1 + number2;
Break
Case 1://-
result = Self.number1-number2;
Break
Case 2://*
result = Self.number1 * NUMBER2;
Break
Case 3:///
result = Self.number1/number2;
Break
}
55+3*2-3/1
Control the number of digits in the decimal point
Self.resultLabel.text = [NSString stringwithformat:@ "%.2f", result];
}
-(ibaction) Number: (UIButton *) Sender {
Take the numbers out and let the labels show.
Remove the title of the button
NSString *title = [Sender titleforstate:uicontrolstatenormal];
Determine if a string starts or ends with * * *
Judging if the button that starts with 0 and the current click is the number is not the decimal point need to remove 0
if (Self.resultlabel.text.length==1 &&![ Title isequaltostring:@ "."] && [Self.resultLabel.text hasprefix:@ "0"]) {
Self.resultLabel.text = @ "";
}
Avoid entering decimal points continuously
if ([title isequaltostring:@.]) {
Determine if a string is included
if ([Self.resultLabel.text rangeofstring:@ "."]. length>0) {
If it contains a. You can't just point it out. The
Return
}
}
Display the title in the lable
Self.resultLabel.text = [Self.resultLabel.textstringByAppendingString:title];
If you enter too much, make the font smaller and the number of rows into countless rows.
if (self.resultlabel.text.length>=8) {
Self.resultLabel.font = [Uifont systemfontofsize:30];
//
Self.resultLabel.numberOfLines = 0;
}
}
IOS Learning Note Interface Graphing Calculator--Lan Yi Education