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:
.