# IOS Learning Note Interface Graphing Calculator--Lan Yi Education

Source: Internet
Author: User

-(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

Related Keywords:
Related Article

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.