回答編集履歴
2
修正
answer
CHANGED
@@ -5,4 +5,39 @@
|
|
5
5
|
or
|
6
6
|
|
7
7
|
imageView.clipsToBounds = true
|
8
|
+
```
|
9
|
+
|
10
|
+
回答追記
|
11
|
+
---
|
12
|
+
|
13
|
+
```swift
|
14
|
+
import UIKit
|
15
|
+
|
16
|
+
class ViewController: UIViewController {
|
17
|
+
|
18
|
+
@IBOutlet weak var imageView: UIImageView!
|
19
|
+
|
20
|
+
override func viewDidLoad() {
|
21
|
+
super.viewDidLoad()
|
22
|
+
|
23
|
+
imageView.image = UIImage(named: "apple")?.resize(imageView.frame.width)
|
24
|
+
imageView.contentMode = .Top
|
25
|
+
imageView.clipsToBounds = true
|
26
|
+
|
27
|
+
print(imageView.image?.size)
|
28
|
+
}
|
29
|
+
}
|
30
|
+
|
31
|
+
extension UIImage {
|
32
|
+
func resize(imageViewWidth: CGFloat) -> UIImage {
|
33
|
+
let ratio = imageViewWidth / self.size.width
|
34
|
+
let resizedSize = CGSize(width: (self.size.width * ratio), height: (self.size.height * ratio))
|
35
|
+
|
36
|
+
UIGraphicsBeginImageContextWithOptions(resizedSize, false, 0.0)
|
37
|
+
drawInRect(CGRect(x: 0, y: 0, width: resizedSize.width, height: resizedSize.height))
|
38
|
+
let resizedImage = UIGraphicsGetImageFromCurrentImageContext()
|
39
|
+
UIGraphicsEndImageContext()
|
40
|
+
return resizedImage
|
41
|
+
}
|
42
|
+
}
|
8
43
|
```
|
1
修正
answer
CHANGED
@@ -1,4 +1,8 @@
|
|
1
1
|
以下の様にするといかがでしょうか?
|
2
2
|
```swift
|
3
3
|
imageView.layer.masksToBounds = true
|
4
|
+
|
5
|
+
or
|
6
|
+
|
7
|
+
imageView.clipsToBounds = true
|
4
8
|
```
|