App程式設計入門#用程式製作國旗
Published in
4 min readAug 1, 2020
選了明年計劃前往的馬爾地夫國旗作為目標!
看到國旗中間的彎月圖案時 …倍感堪憂,但還是決定嘗試挑戰!!
本次練習的參考資料如下:
- 查國旗的色碼:https://www.schemecolor.com/
- 色碼轉RGB的數字代碼(其他同樣功能的網頁很多都可以參考):https://www.ifreesite.com/color/
- 查圖片座標:https://yangcha.github.io/iview/iview.html
- Peter的分解式教學文章:
- 其他學長姐的作業文章:
練習成果!
彎月的部份在調整controlpoint時,無論數字怎麼調仍覺得弧度不夠大,
請教了pater後才明白還有“負數”這個選項。
整體而言還有非常多概念需要再理解與深化!
*最終程式碼*
import UIKitvar rect = CGRect(x: 0, y: 0, width: 718, height: 477)let backgroundView = UIView(frame: rect)backgroundView.backgroundColor = UIColor(red: 203/255, green: 15/255, blue: 50/255, alpha: 1)rect = CGRect(x: 120, y: 120, width: 480, height: 240)let ViewGreen = UIView(frame: rect)ViewGreen.backgroundColor = UIColor(red: 0, green: 126/255, blue: 58/255, alpha: 1)backgroundView.addSubview(ViewGreen)let aDegree = CGFloat.pi / 180let path = UIBezierPath(arcCenter: CGPoint(x: 80, y: 80), radius: 80, startAngle: aDegree * 270, endAngle: aDegree * 90, clockwise: false)path.addQuadCurve(to: CGPoint(x:80, y: 0), controlPoint: CGPoint(x: -25, y: 80))let moonView = UIView(frame: CGRect(x: 309, y: 160, width: 300, height: 160))moonView.backgroundColor = UIColor.whitelet smileShape = CAShapeLayer()smileShape.path = path.cgPathmoonView.layer.mask = smileShapebackgroundView.addSubview(moonView)