반응형
방법 1 :
// Swift (IOS10.3)
extension UIImage {
func combineWith(image: UIImage) -> UIImage {
let size = CGSize(width: self.size.width, height: self.size.height + image.size.height)
UIGraphicsBeginImageContextWithOptions(size, false, 0.0)
self.draw(in: CGRect(x:0 , y: 0, width: size.width, height: self.size.height))
image.draw(in: CGRect(x: 0, y: self.size.height, width: size.width, height: image.size.height))
let newImage: UIImage = UIGraphicsGetImageFromCurrentImageContext()!
UIGraphicsEndImageContext()
return newImage
}
}
// Usage
let image1 = UIImage(named: "image1.jpg")
let image2 = UIImage(named: "image2.jpg")
yourImageView.image = image1?.combineWith(image: image2)
방법 2 :
var bottomImage = UIImage(named: "bottom.png")
var topImage = UIImage(named: "top.png")
var size = CGSize(width: 300, height: 300)
UIGraphicsBeginImageContext(size)
let areaSize = CGRect(x: 0, y: 0, width: size.width, height: size.height)
bottomImage!.draw(in: areaSize)
topImage!.draw(in: areaSize, blendMode: .normal, alpha: 0.8)
var newImage:UIImage = UIGraphicsGetImageFromCurrentImageContext()!
UIGraphicsEndImageContext()
반응형
'개발 > iOS' 카테고리의 다른 글
Firebase dynamic link (다이나믹 링크) (2/4) (0) | 2021.06.17 |
---|---|
Firebase dynamic link (다이나믹 링크) (1/4) (2) | 2021.06.17 |
시간 지연 함수 (0) | 2021.03.18 |
경과 시간 구하기 (0) | 2021.03.18 |
스크린 안꺼지게 하기 (0) | 2021.03.18 |