@@ -21,6 +21,7 @@ final class RecipeDetailView: UIView {
21
21
override init ( frame: CGRect ) {
22
22
super. init ( frame: frame)
23
23
setupUI ( )
24
+ setupLayout ( )
24
25
}
25
26
26
27
required init ? ( coder: NSCoder ) {
@@ -29,22 +30,12 @@ final class RecipeDetailView: UIView {
29
30
30
31
private func setupUI( ) {
31
32
backgroundColor = . white
32
- addSubview ( scrollView)
33
- addSubview ( pageControl)
34
- addSubview ( recipeNameLabel)
35
- addSubview ( recipeDescriptionLabel)
36
- addSubview ( photoIndexLabel)
37
-
38
- scrollView. translatesAutoresizingMaskIntoConstraints = false
39
- pageControl. translatesAutoresizingMaskIntoConstraints = false
40
- recipeNameLabel. translatesAutoresizingMaskIntoConstraints = false
41
- recipeDescriptionLabel. translatesAutoresizingMaskIntoConstraints = false
42
- photoIndexLabel. translatesAutoresizingMaskIntoConstraints = false
43
-
44
- scrollView. isPagingEnabled = true
45
- scrollView. showsHorizontalScrollIndicator = false
46
- scrollView. delegate = self
33
+ setupScrollView ( )
34
+ setupPageControl ( )
35
+ setupLabels ( )
36
+ }
47
37
38
+ private func setupLayout( ) {
48
39
NSLayoutConstraint . activate ( [
49
40
scrollView. topAnchor. constraint ( equalTo: safeAreaLayoutGuide. topAnchor) ,
50
41
scrollView. leadingAnchor. constraint ( equalTo: leadingAnchor) ,
@@ -65,6 +56,29 @@ final class RecipeDetailView: UIView {
65
56
recipeDescriptionLabel. leadingAnchor. constraint ( equalTo: leadingAnchor, constant: 20 ) ,
66
57
recipeDescriptionLabel. trailingAnchor. constraint ( equalTo: trailingAnchor, constant: - 20 )
67
58
] )
59
+ }
60
+
61
+ private func setupScrollView( ) {
62
+ addSubview ( scrollView)
63
+ scrollView. translatesAutoresizingMaskIntoConstraints = false
64
+ scrollView. isPagingEnabled = true
65
+ scrollView. showsHorizontalScrollIndicator = false
66
+ scrollView. delegate = self
67
+ }
68
+
69
+ private func setupPageControl( ) {
70
+ addSubview ( pageControl)
71
+ pageControl. translatesAutoresizingMaskIntoConstraints = false
72
+ }
73
+
74
+ private func setupLabels( ) {
75
+ addSubview ( recipeNameLabel)
76
+ addSubview ( recipeDescriptionLabel)
77
+ addSubview ( photoIndexLabel)
78
+
79
+ recipeNameLabel. translatesAutoresizingMaskIntoConstraints = false
80
+ recipeDescriptionLabel. translatesAutoresizingMaskIntoConstraints = false
81
+ photoIndexLabel. translatesAutoresizingMaskIntoConstraints = false
68
82
69
83
recipeNameLabel. font = Fonts . DetailtitleFont
70
84
recipeNameLabel. numberOfLines = 0
@@ -76,12 +90,12 @@ final class RecipeDetailView: UIView {
76
90
func configure( with viewModel: RecipeDetailViewModel ) {
77
91
recipeNameLabel. text = viewModel. RecipeName
78
92
recipeDescriptionLabel. text = viewModel. RecipeDescription
79
- setupScrollView ( with: viewModel. RecipeImageUrls)
93
+ setupScrollViewContent ( with: viewModel. RecipeImageUrls)
80
94
pageControl. numberOfPages = viewModel. RecipeImageUrls. count
81
95
updatePhotoIndexLabel ( currentPage: 0 )
82
96
}
83
97
84
- private func setupScrollView ( with recipeImageUrls: [ URL ] ) {
98
+ private func setupScrollViewContent ( with recipeImageUrls: [ URL ] ) {
85
99
guard !imagesAdded else { return }
86
100
let imageViewWidth = UIScreen . main. bounds. width
87
101
0 commit comments