IOS development case study: Judging Chinese zodiac by year

Source: Internet
Author: User

IOS development case study: Judging Chinese zodiac by year

To write this blog, first of all, I would like to thank Lin Yongjian, who wrote this blog after reading Miss Lin's video course. Thank you very much.

The requirement is as follows: Enter the year, click the button, and then judge the Chinese zodiac Based on the Year, and display a picture of the Chinese zodiac. The development procedure is as follows:

(1) first, prepare 12 images, representing 12 Chinese zodiac signs. The image numbers are respectively 0--11

(2) drag three controls into the Main. storyboard, enter the year in Text Field, click the Button, and the ImageView displays the Zodiac image. The interface is as follows:

.

 

(3) Press and hold the control key and the left mouse button, select outlets, drag the input box and image controls to the. swift file, and generate the declaration of these controls in the code.

.

 

(4) drag the button to the Code in the preceding way. Select Action.

 

(5) how to combine the Chinese zodiac and pictures of a year. The algorithm is as follows: Image number = (year-4) % 12. In this way, you can easily create realistic images. Add the calculation to the Click Event of the button. The code for clicking the button is as follows:

.

 

(6) output result:

.

 

 

 

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.