#12從程式製作簡易國旗圖案
Published in
6 min readAug 12, 2021
1.立陶宛
程式碼:
import UIKitimport PlaygroundSupportlet rect1 = CGRect(x: 0, y: 0, width: 600, height: 402)let flag = UIView(frame: rect1)let rect2 = CGRect(x: 0, y: 0, width: 600, height: 134)let yellowRectView = UIView(frame: rect2)yellowRectView.layer.backgroundColor = UIColor(red: 253/255, green: 185/255, blue: 19/255, alpha: 1).cgColorlet rect3 = CGRect(x: 0, y: 134, width: 600, height: 134)let greenRectView = UIView(frame: rect3)greenRectView.layer.backgroundColor = UIColor(red: 0, green: 106/255, blue: 68/255, alpha: 1).cgColorlet rect4 = CGRect(x: 0, y: 268, width: 600, height: 134)let redRectView = UIView(frame: rect4)redRectView.layer.backgroundColor = UIColor(red: 193/255, green: 39/255, blue: 45/255, alpha: 1).cgColorflag.addSubview(yellowRectView)
flag.addSubview(greenRectView)
flag.addSubview(redRectView)
PlaygroundPage.current.liveView = flag
2.日本
程式碼:
import UIKitimport PlaygroundSupportlet rect = CGRect(x: 0, y: 0, width: 600, height: 400)let flag = UIView(frame: rect)flag.layer.backgroundColor = UIColor(red: 1, green: 1, blue: 1, alpha: 1).cgColorlet circle = CGRect(x: 200, y: 100, width: 200, height: 200)let redCircle = UIView(frame: circle)redCircle.layer.cornerRadius = 100redCircle.layer.backgroundColor = UIColor(red: 1, green: 0, blue: 0, alpha: 1).cgColorflag.layer.borderWidth = 1
flag.layer.borderColor = UIColor(red: 214/255, green: 214/255, blue: 214/255, alpha: 1).cgColorflag.addSubview(redCircle)
PlaygroundPage.current.liveView = flag
3.法國
程式碼:
import UIKitimport PlaygroundSupportlet rect1 = CGRect(x: 0, y: 0, width: 600, height: 400)let flag = UIView(frame: rect1)let rect2 = CGRect(x: 0, y: 0, width: 200, height: 400)let blueRectView = UIView(frame: rect2)blueRectView.layer.backgroundColor = UIColor(red: 0, green: 85/255, blue: 164/255, alpha: 1).cgColorlet rect3 = CGRect(x: 200, y: 0, width: 200, height: 400)let whiteRectView = UIView(frame: rect3)whiteRectView.layer.backgroundColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0).cgColorlet rect4 = CGRect(x: 400, y: 0, width: 200, height: 400)let redRectView = UIView(frame: rect4)redRectView.layer.backgroundColor = UIColor(red: 239/255, green: 65/255, blue: 53/255, alpha: 1).cgColorflag.addSubview(blueRectView)
flag.addSubview(whiteRectView)
flag.addSubview(redRectView)
PlaygroundPage.current.liveView = flag
參考資料: