Day10
Lectures ten days, today mainly about the iOS calculator program writing, which contains the new code is quite a lot of, and need to seriously think, organizational logic of the place also many. Summarize some of the code that needs to be understood and applied.
Control the number of digits in the decimal point
Self.resultLabel.text = [nsstringstringwithformat:@ "%.2f", result];
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.textrangeofstring:@ "."]. 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;
}
}
Lan Yi Education Calculator compilation