Lan Yi Education Calculator compilation

Source: Internet
Author: User

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

Related Article

Contact Us

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.