#13利用 mask 設計特別形狀的圖片

  1. 利用 UIView 的 mask 設計特別形狀的圖片,並且改變圖片的顏色

程式碼:

import UIKitlet girlImage = UIImage(named: "girl.jpg")
let girlImageView = UIImageView(image: girlImage)
let catImage = UIImage(named: "cat.png")
let catImageView1 = UIImageView(image: catImage)
girlImageView.mask = catImageView1let redView = UIView(frame: girlImageView.frame)
redView.backgroundColor = UIColor(red: 1, green: 0, blue: 0, alpha: 0.5)
let catImageView2 = UIImageView(image: catImage)redView.mask = catImageView2girlImageView.addSubview(redView)

2.利用 UIView 的 mask 設計特別形狀的圖片,並且融合兩張照片

import UIKitlet girlImage = UIImage(named: "girl.jpg")
let girlImageView = UIImageView(image: girlImage)
let catImage = UIImage(named: "cat")
let catImageView1 = UIImageView(image: catImage)
girlImageView.mask = catImageView1
girlImageView.alpha = 0.5
let dogImage = UIImage(named: "dog.jpg")
let dogImageView = UIImageView(image: dogImage)
dogImageView.alpha = 0.2
dogImageView.frame = CGRect(x: 0, y: 0, width: 1000, height: 900)
let catImageView2 = UIImageView(image: catImage)dogImageView.mask = catImageView2let backgroundView = UIView(frame: girlImageView.frame)backgroundView.addSubview(girlImageView)
backgroundView.addSubview(dogImageView)

參考資料:

--

--