#19製作特別的圖片(playground)

☀︎成品:

import UIKit
//加入圖片
let sunImage = UIImage(named: "sun.jpg")
let handImage = UIImage(named: "hand.png")
let sunView = UIImageView(image: sunImage)
let handView = UIImageView(image: handImage)
//設定文字框架大小
let messageLabel = UILabel(frame: CGRect(x: 450, y: 200, width: 1000, height: 500))
messageLabel.text = "落日餘暉"
//文字顏色
messageLabel.textColor = UIColor(red: 255/255, green: 193/255, blue: 100/255, alpha: 1)
//文字大小
messageLabel.font = UIFont.systemFont(ofSize: 150)
sunView.addSubview(messageLabel)
//邊框寬度及顏色
sunView.layer.borderWidth = 7
sunView.layer.borderColor = CGColor(red: 0, green: 200/255, blue: 200/255, alpha: 0.5)
//設定圓角
sunView.layer.cornerRadius = 50
sunView.clipsToBounds = true

//維持圖片比例且填滿
handView.contentMode = .scaleAspectFill
//調整view大小
handView.frame = CGRect(x: 400, y: 1300, width: 700, height: 700)
//日落中加入剪影
sunView.addSubview(handView)

☀︎練習項目:如上

☀︎︎成品:

//加入圖片
let sunImage = UIImage(named: "sun.jpg")
let handImage = UIImage(named: "hand.png")
let sunView = UIImageView(image: sunImage)
let handView = UIImageView(image: handImage)
//維持圖片比例且填滿
handView.contentMode = .scaleAspectFill
//.frame調整大小位置
handView.frame = CGRect(x: 0, y: 50, width: 1500, height: 2000)
//sun的遮罩為剪影圖
sunView.mask = handView
//透明度
sunView.alpha = 0.7
//圓角
sunView.layer.cornerRadius = 50
sunView.clipsToBounds = true

☀︎練習項目:使用Mask

--

--