從程式製作國旗圖案-法國國旗
這次作業選擇了
象徵著自由、平等、博愛的法國國旗
因為他比較簡單(很誠實😂)
廢話不多說 以下是程式碼
import UIKit
import PlaygroundSupport
//建立矩形
var rect = CGRect(x: 0, y: 0, width: 600, height: 300)
//建立藍色view
let blueView = UIView(frame: rect)
blueView.backgroundColor = UIColor(red: 0, green: 0, blue: 1, alpha: 1)
//建立白色view
rect = CGRect(x: 200, y: 0, width: 200, height: 300)
let whiteview = UIView(frame: rect)
whiteview.backgroundColor = UIColor(red: 1, green: 1, blue: 1, alpha: 1)
//藍色view加入一個白色view
blueView.addSubview(whiteview)
//建立紅色view
rect = CGRect(x: 400, y: 0, width: 200, height: 300)
let redview = UIView(frame: rect)
redview.backgroundColor = UIColor(red: 1, green: 0, blue: 0, alpha: 1)
//藍色view加入一個紅色view
blueView.addSubview(redview)
//Playground liveview
PlaygroundPage.current.liveView = blueView
簡單來說 就是 全部摻在一起 做成法國國旗~
參考資料