Playground を利用して画像を部分的に切り抜いてみます。
画像はこちらの記事で利用したものをそのまま使います。
まずはサイズの確認から
let image = UIImage(named: "sample.png")!
print(image.size) // (300.0, 212.0)
切り取るサイズを指定して UIImage として抽出してみます。
let clipRect = CGRect(x: 0, y: 0, width: 300, height: 100)
let cripImageRef = image.cgImage!.cropping(to: clipRect)
let crippedImage = UIImage(cgImage: cripImageRef!)
生成した UIImage を表示してみます
let imageView = UIImageView(image: crippedImage)
imageView.frame = CGRect(x: 0, y: 0, width: 300, height: 212)
imageView.contentMode = .scaleAspectFit
imageView.backgroundColor = .white
PlaygroundPage.current.liveView = imageView
このような感じで表示されます。
当社で開発した予定とタスクを同時に管理できるiOSアプリ「My Schedule - マイスケジュール -」をリリースしました。ダウンロード&評価のほどよろしくお願いいたします。