利用 UIView 的 mask 設計特別形狀的圖片
Published in
2 min readApr 6, 2019
利用皮卡丘剪影+寶可夢圖鑑+紅幕+草地照片疊在一起
其中用到mask及subview
import UIKitlet pikachuImage = UIImage(named: “pikachu.png”)let pikachuImageView1 = UIImageView(image: pikachuImage)let pokemonImage = UIImage(named: “pokemon.jpeg”)let pokemonImageView = UIImageView(image: pokemonImage)pokemonImageView.mask = pikachuImageView1let grasslandImage = UIImage(named: “grassland.jpeg”)let grasslandImageView = UIImageView(image: grasslandImage)let redView = UIView(frame: pokemonImageView.frame)redView.backgroundColor = UIColor(red: 1, green: 0, blue: 0, alpha: 0.2)let pikachuImageView2 = UIImageView(image: pikachuImage)redView.mask = pikachuImageView2pokemonImageView.addSubview(redView)grasslandImageView.mask=pikachuImageView2grasslandImageView.alpha=0.5pokemonImageView.alpha=0.5let backgroundImageView = UIView(frame: pokemonImageView.frame)backgroundImageView.addSubview(grasslandImageView)backgroundImageView.addSubview(pokemonImageView)
成圖如下方