APP實作 — 顏色變化第二彈

上一次做了簡單的顏色更換,這次針對改色彩做了一點點不太一樣的方式。

不囉唆,先上圖

這次新加入了兩個功能,一個是亂數顯示小人物帽子的顏色和亂數顯示天氣。第二個是點選帽子的時候,除了帽子顏色會更換,天氣也會更換歐。

這次製作圖片的Sample 還是記錄一下好了

var arrayWeather = [“weatherA”,”weatherB”,”weatherC”,”weatherD”,”weatherE”,”weatherE”,”weatherG”]

let image = UIImage(named:arrayWeather[Int(arc4random_uniform(6))])

let frameRect: CGRect = CGRect(x: 30, y: 80, width: 100, height: 100)

var imageView = UIImageView(frame:frameRect)

imageView.image = image

imageView.contentMode = .scaleAspectFit

view.addSubview(imageView)

以下是小註解

Int(arc4random_uniform(6))是亂數產生0~6的數字

CGRect(x: 30, y: 80, width: 100, height: 100)是指定圖片要出現在畫面哪個位置和圖片大小

好拉,小小作業就完成瞜。

--

--