HW#26 Using Code to Make a Card

I can’t believe our class ended today. Wow, what a journey! I really learnt a great deal of stuff. This iOS App course truly is amazing and entertaining. No wonder even Bill Gates and Mr. Obama have highly recommended learning how to code. I reckon that living in this high-tech era, we should at least have some fundamental understanding about Apps, coding, and computer science.

Reflecting back on the preliminary stage in this class, I was anxious and panicked about the course content because I had never learnt anything regarding computer science and coding. I even bought some books to read although they’re not easy.

Fortunately, our lecturer, Peter, knows how to explain things clearly and patiently. Hence we learnt step by step and improved gradually. When I was an undergraduate, I started to write my own blog, penning down significant or interesting events happened in life. Certainly, it was such a craze that many people wrote blog entries to share their thoughts, highs and lows in life, or complaints. If you didn’t have a blog, you would be regarded as “outdated”, lol. Of course, we know that after Facebook became prevalent, blogs slowly faded away.

So, it is a bit surprising that I resumed writing blog entries after such a long time; however, this time it is for recording what I’ve learnt in my App class and documenting the steps of assignments. How thrilling it has been; and inconceivably I have written 25 blog entries on Medium so far.

Today, I am going to demonstrate another simple but quite meaningful assignment. Using code to make a card. At the beginning of this course, we learnt how to make a card using Storyboard, which did not require code writing. This time, I would use simple code to do the same sort of homework. Therefore I decided to make a card so I can send it to my good friends in Thailand next year.

  1. Pick a lotus image. This flower has significantly important meaning in Thailand because Buddhism is the biggest religion there; and one can see lotus flowers everywhere they go. Lotus flower is considered as a symbol of purity, enlightenment, self-regeneration and rebirth. Its characteristics are an excellent analogy for the human condition: even when its roots are in the dirtiest waters, the lotus produces the most stunning flower.

Then, we need to key out the background. If you’re on a Mac, it is relatively easy to do so.

2. Choose a temple photo. I took this picture a few years back when I went to Chiang Rai, Thailand. There are loads of temples in Thailand. The dazzling golden colour in the sun is something I’ll never forget. With the freezing and humid weather now, I really miss the sunny and warm Thailand.

3. For this assignment, I also checked some seniors’ works. The links are as follows:

More importantly, I practiced using Mask, Frame, CornerRadius, CGAffineTransform to make the card. Of course, in the code, I got to utilize for loops again! It is just much more convenient and save a lot of space. For instance:

for i in 1..<9 {

let lilyLeafImageView = UIImageView(image: UIImage(named: “lily-leaf”))

lilyLeafImageView.frame = CGRect(x: 0, y: i*iconSize, width: iconSize, height: iconSize)

lilyLeafImageView.transform = CGAffineTransform(rotationAngle: CGFloat.random(in: 0…(.pi*2)))

cardView.addSubview(lilyLeafImageView)

}

I did enjoy making this card for I had to use many things we have learnt throughout this entire course. It’s a bit of recap of many skills. The only thing I had to spend more time was adjusting the frame with the little lotus flowers over the boarders of the card.

4. Now, let’s take a look at the code I wrote.

Part I
Part II

5. I added สวัสดีปีใหม่ on the card. It means Happy New Year in Thai.

6. As for the Chinese character, , it means lotus flower.

7. Here is the final result of the card.

Last but not the least, many thanks to Peter and a lot of seniors’ fantastic assignments. This App journey that I embarked upon will continue; and I sure hope in the near future, I am able to design some fun Apps. Cheers! Happy Coding.

--

--

Jerski
彼得潘的 Swift iOS / Flutter App 開發教室

Studied Linguistics in university and have been intrigued by code writing. Now this journey of Swift just began.