回答編集履歴
4
整理整頓
test
CHANGED
@@ -1,8 +1,30 @@
|
|
1
|
-
|
1
|
+
# resize(size:)の修正
|
2
2
|
|
3
3
|
|
4
4
|
|
5
|
+
指定サイズの描画領域を用意し、その中央にリサイズ後の画像を描画するようにします。
|
6
|
+
|
5
|
-
|
7
|
+
参考記事の該当部分を置き換えて下さい。
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
```swift
|
12
|
+
|
13
|
+
UIGraphicsBeginImageContextWithOptions(size, false, 0.0)
|
14
|
+
|
15
|
+
draw(in: CGRect(x: (size.width - resizedSize.width) / 2, y: (size.height - resizedSize.height) / 2, width: resizedSize.width, height: resizedSize.height))
|
16
|
+
|
17
|
+
```
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
# 画像の設定
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
サイズは200x100を想定しています。
|
26
|
+
|
27
|
+
frameやcontentModeなどの設定は不要で、imageの設定のみで大丈夫です。
|
6
28
|
|
7
29
|
|
8
30
|
|
@@ -21,27 +43,3 @@
|
|
21
43
|
}
|
22
44
|
|
23
45
|
```
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
だけにするとどうなりますか?出来ればスクショを貼って下さい。
|
28
|
-
|
29
|
-
(サイズは200x100を想定しています)
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
# resize(size:)の修正
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
指定サイズの描画領域を用意し、その中央にリサイズ後の画像を描画するようにします。
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
```swift
|
42
|
-
|
43
|
-
UIGraphicsBeginImageContextWithOptions(size, false, 0.0)
|
44
|
-
|
45
|
-
draw(in: CGRect(x: (size.width - resizedSize.width) / 2, y: (size.height - resizedSize.height) / 2, width: resizedSize.width, height: resizedSize.height))
|
46
|
-
|
47
|
-
```
|
3
最適化
test
CHANGED
@@ -11,10 +11,6 @@
|
|
11
11
|
if let image = UIImage(contentsOfFile: pth) {
|
12
12
|
|
13
13
|
cell.imageView?.image = image.resize(size: CGSize(width: 200, height: 100))
|
14
|
-
|
15
|
-
//cell.imageView?.frame = CGRect(x: 0, y: 0, width: 200, height: 100)
|
16
|
-
|
17
|
-
cell.contentMode = .scaleAspectFit
|
18
14
|
|
19
15
|
|
20
16
|
|
@@ -38,6 +34,10 @@
|
|
38
34
|
|
39
35
|
|
40
36
|
|
37
|
+
指定サイズの描画領域を用意し、その中央にリサイズ後の画像を描画するようにします。
|
38
|
+
|
39
|
+
|
40
|
+
|
41
41
|
```swift
|
42
42
|
|
43
43
|
UIGraphicsBeginImageContextWithOptions(size, false, 0.0)
|
2
resize
test
CHANGED
@@ -31,3 +31,17 @@
|
|
31
31
|
だけにするとどうなりますか?出来ればスクショを貼って下さい。
|
32
32
|
|
33
33
|
(サイズは200x100を想定しています)
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
# resize(size:)の修正
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
```swift
|
42
|
+
|
43
|
+
UIGraphicsBeginImageContextWithOptions(size, false, 0.0)
|
44
|
+
|
45
|
+
draw(in: CGRect(x: (size.width - resizedSize.width) / 2, y: (size.height - resizedSize.height) / 2, width: resizedSize.width, height: resizedSize.height))
|
46
|
+
|
47
|
+
```
|
1
リサイズ
test
CHANGED
@@ -8,17 +8,21 @@
|
|
8
8
|
|
9
9
|
```swift
|
10
10
|
|
11
|
-
|
11
|
+
if let image = UIImage(contentsOfFile: pth) {
|
12
12
|
|
13
|
-
cell.imageView?.
|
13
|
+
cell.imageView?.image = image.resize(size: CGSize(width: 200, height: 100))
|
14
14
|
|
15
|
-
cell.
|
15
|
+
//cell.imageView?.frame = CGRect(x: 0, y: 0, width: 200, height: 100)
|
16
16
|
|
17
|
-
|
17
|
+
cell.contentMode = .scaleAspectFit
|
18
18
|
|
19
|
-
cell.imageView?.layer.borderColor = UIColor.red.cgColor
|
20
19
|
|
20
|
+
|
21
|
+
cell.imageView?.layer.borderColor = UIColor.red.cgColor
|
22
|
+
|
21
|
-
cell.imageView?.layer.borderWidth = 1
|
23
|
+
cell.imageView?.layer.borderWidth = 1
|
24
|
+
|
25
|
+
}
|
22
26
|
|
23
27
|
```
|
24
28
|
|