diff --git a/MarvelApp.xcodeproj/project.pbxproj b/MarvelApp.xcodeproj/project.pbxproj index a25107f..1ae928a 100644 --- a/MarvelApp.xcodeproj/project.pbxproj +++ b/MarvelApp.xcodeproj/project.pbxproj @@ -18,8 +18,9 @@ AD37543029A39A970081B177 /* MarvelAppTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = AD37542F29A39A970081B177 /* MarvelAppTests.swift */; }; AD37543A29A39A970081B177 /* MarvelAppUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = AD37543929A39A970081B177 /* MarvelAppUITests.swift */; }; AD37543C29A39A970081B177 /* MarvelAppUITestsLaunchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = AD37543B29A39A970081B177 /* MarvelAppUITestsLaunchTests.swift */; }; - AD5B6EDA29A50A29005B0C6C /* HeroesCardsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = AD5B6ED929A50A29005B0C6C /* HeroesCardsView.swift */; }; AD5EA00829A560AC0033A503 /* MyCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = AD5EA00729A560AC0033A503 /* MyCell.swift */; }; + AD5EA00A29AC8C950033A503 /* HeroData.swift in Sources */ = {isa = PBXBuildFile; fileRef = AD5EA00929AC8C950033A503 /* HeroData.swift */; }; + AD5EA00E29AD42150033A503 /* PathView.swift in Sources */ = {isa = PBXBuildFile; fileRef = AD5EA00D29AD42150033A503 /* PathView.swift */; }; CA7004ABCE93D9090970795E /* Pods_MarvelAppTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3E6C5312B6EA2F0A45BEE376 /* Pods_MarvelAppTests.framework */; }; /* End PBXBuildFile section */ @@ -59,8 +60,9 @@ AD37543529A39A970081B177 /* MarvelAppUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = MarvelAppUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; AD37543929A39A970081B177 /* MarvelAppUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MarvelAppUITests.swift; sourceTree = ""; }; AD37543B29A39A970081B177 /* MarvelAppUITestsLaunchTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MarvelAppUITestsLaunchTests.swift; sourceTree = ""; }; - AD5B6ED929A50A29005B0C6C /* HeroesCardsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HeroesCardsView.swift; sourceTree = ""; }; AD5EA00729A560AC0033A503 /* MyCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyCell.swift; sourceTree = ""; }; + AD5EA00929AC8C950033A503 /* HeroData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HeroData.swift; sourceTree = ""; }; + AD5EA00D29AD42150033A503 /* PathView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PathView.swift; sourceTree = ""; }; BB7ABF690408B08F32139BA0 /* Pods_MarvelApp_MarvelAppUITests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_MarvelApp_MarvelAppUITests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; D658C792CA6F53A8DFB61347 /* Pods-MarvelApp.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-MarvelApp.debug.xcconfig"; path = "Target Support Files/Pods-MarvelApp/Pods-MarvelApp.debug.xcconfig"; sourceTree = ""; }; F8612523AC76E5A843A80D87 /* Pods_MarvelApp.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_MarvelApp.framework; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -150,8 +152,9 @@ AD37542129A39A960081B177 /* Assets.xcassets */, AD37542329A39A960081B177 /* LaunchScreen.storyboard */, AD37542629A39A960081B177 /* Info.plist */, - AD5B6ED929A50A29005B0C6C /* HeroesCardsView.swift */, AD5EA00729A560AC0033A503 /* MyCell.swift */, + AD5EA00929AC8C950033A503 /* HeroData.swift */, + AD5EA00D29AD42150033A503 /* PathView.swift */, ); path = MarvelApp; sourceTree = ""; @@ -414,8 +417,9 @@ files = ( AD37541D29A39A940081B177 /* ViewController.swift in Sources */, AD5EA00829A560AC0033A503 /* MyCell.swift in Sources */, + AD5EA00A29AC8C950033A503 /* HeroData.swift in Sources */, + AD5EA00E29AD42150033A503 /* PathView.swift in Sources */, AD37541929A39A940081B177 /* AppDelegate.swift in Sources */, - AD5B6EDA29A50A29005B0C6C /* HeroesCardsView.swift in Sources */, AD37541B29A39A940081B177 /* SceneDelegate.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/MarvelApp/AppDelegate.swift b/MarvelApp/AppDelegate.swift index 5210d41..f7f60fd 100644 --- a/MarvelApp/AppDelegate.swift +++ b/MarvelApp/AppDelegate.swift @@ -1,10 +1,3 @@ -// -// AppDelegate.swift -// MarvelApp -// -// Created by effective_macbook_pro on 20.02.2023. -// - import UIKit @main @@ -14,7 +7,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. - print(1) return true } diff --git a/MarvelApp/Assets.xcassets/CaptainAmerica.colorset/Contents.json b/MarvelApp/Assets.xcassets/CaptainAmerica.colorset/Contents.json new file mode 100644 index 0000000..a5ed59e --- /dev/null +++ b/MarvelApp/Assets.xcassets/CaptainAmerica.colorset/Contents.json @@ -0,0 +1,38 @@ +{ + "colors" : [ + { + "color" : { + "color-space" : "srgb", + "components" : { + "alpha" : "1.000", + "blue" : "1.000", + "green" : "0.500", + "red" : "0.302" + } + }, + "idiom" : "universal" + }, + { + "appearances" : [ + { + "appearance" : "luminosity", + "value" : "dark" + } + ], + "color" : { + "color-space" : "srgb", + "components" : { + "alpha" : "1.000", + "blue" : "1.000", + "green" : "1.000", + "red" : "1.000" + } + }, + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/MarvelApp/Assets.xcassets/CaptainAmerica.imageset/Contents.json b/MarvelApp/Assets.xcassets/CaptainAmerica.imageset/Contents.json new file mode 100644 index 0000000..17e8493 --- /dev/null +++ b/MarvelApp/Assets.xcassets/CaptainAmerica.imageset/Contents.json @@ -0,0 +1,22 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x" + }, + { + "filename" : "captain-america-png-from-pngfre-9-821x1024-1.png", + "idiom" : "universal", + "scale" : "2x" + }, + { + "filename" : "captain-america-png-from-pngfre-9-821x1024-2.png", + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/MarvelApp/Assets.xcassets/CaptainAmerica.imageset/captain-america-png-from-pngfre-9-821x1024-1.png b/MarvelApp/Assets.xcassets/CaptainAmerica.imageset/captain-america-png-from-pngfre-9-821x1024-1.png new file mode 100644 index 0000000..83dc98f Binary files /dev/null and b/MarvelApp/Assets.xcassets/CaptainAmerica.imageset/captain-america-png-from-pngfre-9-821x1024-1.png differ diff --git a/MarvelApp/Assets.xcassets/CaptainAmerica.imageset/captain-america-png-from-pngfre-9-821x1024-2.png b/MarvelApp/Assets.xcassets/CaptainAmerica.imageset/captain-america-png-from-pngfre-9-821x1024-2.png new file mode 100644 index 0000000..83dc98f Binary files /dev/null and b/MarvelApp/Assets.xcassets/CaptainAmerica.imageset/captain-america-png-from-pngfre-9-821x1024-2.png differ diff --git a/MarvelApp/Assets.xcassets/Deadpool.colorset/Contents.json b/MarvelApp/Assets.xcassets/Deadpool.colorset/Contents.json new file mode 100644 index 0000000..7631e69 --- /dev/null +++ b/MarvelApp/Assets.xcassets/Deadpool.colorset/Contents.json @@ -0,0 +1,38 @@ +{ + "colors" : [ + { + "color" : { + "color-space" : "srgb", + "components" : { + "alpha" : "1.000", + "blue" : "0.011", + "green" : "0.000", + "red" : "1.000" + } + }, + "idiom" : "universal" + }, + { + "appearances" : [ + { + "appearance" : "luminosity", + "value" : "dark" + } + ], + "color" : { + "color-space" : "srgb", + "components" : { + "alpha" : "1.000", + "blue" : "1.000", + "green" : "1.000", + "red" : "1.000" + } + }, + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/MarvelApp/Assets.xcassets/Deadpool.imageset/Contents.json b/MarvelApp/Assets.xcassets/Deadpool.imageset/Contents.json new file mode 100644 index 0000000..9d4fd38 --- /dev/null +++ b/MarvelApp/Assets.xcassets/Deadpool.imageset/Contents.json @@ -0,0 +1,22 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x" + }, + { + "filename" : "Deadpool-PNG-1.png", + "idiom" : "universal", + "scale" : "2x" + }, + { + "filename" : "Deadpool-PNG-2.png", + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/MarvelApp/Assets.xcassets/Deadpool.imageset/Deadpool-PNG-1.png b/MarvelApp/Assets.xcassets/Deadpool.imageset/Deadpool-PNG-1.png new file mode 100644 index 0000000..233254a Binary files /dev/null and b/MarvelApp/Assets.xcassets/Deadpool.imageset/Deadpool-PNG-1.png differ diff --git a/MarvelApp/Assets.xcassets/Deadpool.imageset/Deadpool-PNG-2.png b/MarvelApp/Assets.xcassets/Deadpool.imageset/Deadpool-PNG-2.png new file mode 100644 index 0000000..233254a Binary files /dev/null and b/MarvelApp/Assets.xcassets/Deadpool.imageset/Deadpool-PNG-2.png differ diff --git a/MarvelApp/Assets.xcassets/DoctorStrange.colorset/Contents.json b/MarvelApp/Assets.xcassets/DoctorStrange.colorset/Contents.json new file mode 100644 index 0000000..81b4caa --- /dev/null +++ b/MarvelApp/Assets.xcassets/DoctorStrange.colorset/Contents.json @@ -0,0 +1,38 @@ +{ + "colors" : [ + { + "color" : { + "color-space" : "srgb", + "components" : { + "alpha" : "1.000", + "blue" : "0.644", + "green" : "1.000", + "red" : "0.386" + } + }, + "idiom" : "universal" + }, + { + "appearances" : [ + { + "appearance" : "luminosity", + "value" : "dark" + } + ], + "color" : { + "color-space" : "srgb", + "components" : { + "alpha" : "1.000", + "blue" : "1.000", + "green" : "1.000", + "red" : "1.000" + } + }, + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/MarvelApp/Assets.xcassets/DoctorStrange.imageset/Contents.json b/MarvelApp/Assets.xcassets/DoctorStrange.imageset/Contents.json new file mode 100644 index 0000000..51423bf --- /dev/null +++ b/MarvelApp/Assets.xcassets/DoctorStrange.imageset/Contents.json @@ -0,0 +1,22 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x" + }, + { + "filename" : "Marvel-Doctor-Strange-1.png", + "idiom" : "universal", + "scale" : "2x" + }, + { + "filename" : "Marvel-Doctor-Strange-2.png", + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/MarvelApp/Assets.xcassets/DoctorStrange.imageset/Marvel-Doctor-Strange-1.png b/MarvelApp/Assets.xcassets/DoctorStrange.imageset/Marvel-Doctor-Strange-1.png new file mode 100644 index 0000000..e7507ca Binary files /dev/null and b/MarvelApp/Assets.xcassets/DoctorStrange.imageset/Marvel-Doctor-Strange-1.png differ diff --git a/MarvelApp/Assets.xcassets/DoctorStrange.imageset/Marvel-Doctor-Strange-2.png b/MarvelApp/Assets.xcassets/DoctorStrange.imageset/Marvel-Doctor-Strange-2.png new file mode 100644 index 0000000..e7507ca Binary files /dev/null and b/MarvelApp/Assets.xcassets/DoctorStrange.imageset/Marvel-Doctor-Strange-2.png differ diff --git a/MarvelApp/Assets.xcassets/IronMan.colorset/Contents.json b/MarvelApp/Assets.xcassets/IronMan.colorset/Contents.json new file mode 100644 index 0000000..a35d865 --- /dev/null +++ b/MarvelApp/Assets.xcassets/IronMan.colorset/Contents.json @@ -0,0 +1,38 @@ +{ + "colors" : [ + { + "color" : { + "color-space" : "srgb", + "components" : { + "alpha" : "1.000", + "blue" : "0.308", + "green" : "0.450", + "red" : "1.000" + } + }, + "idiom" : "universal" + }, + { + "appearances" : [ + { + "appearance" : "luminosity", + "value" : "dark" + } + ], + "color" : { + "color-space" : "srgb", + "components" : { + "alpha" : "1.000", + "blue" : "1.000", + "green" : "1.000", + "red" : "1.000" + } + }, + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/MarvelApp/Assets.xcassets/IronMan.imageset/Contents.json b/MarvelApp/Assets.xcassets/IronMan.imageset/Contents.json new file mode 100644 index 0000000..27d6bf3 --- /dev/null +++ b/MarvelApp/Assets.xcassets/IronMan.imageset/Contents.json @@ -0,0 +1,22 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x" + }, + { + "filename" : "iron-man-png-11.png", + "idiom" : "universal", + "scale" : "2x" + }, + { + "filename" : "iron-man-png-12.png", + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/MarvelApp/Assets.xcassets/IronMan.imageset/iron-man-png-11.png b/MarvelApp/Assets.xcassets/IronMan.imageset/iron-man-png-11.png new file mode 100644 index 0000000..22f1f3b Binary files /dev/null and b/MarvelApp/Assets.xcassets/IronMan.imageset/iron-man-png-11.png differ diff --git a/MarvelApp/Assets.xcassets/IronMan.imageset/iron-man-png-12.png b/MarvelApp/Assets.xcassets/IronMan.imageset/iron-man-png-12.png new file mode 100644 index 0000000..22f1f3b Binary files /dev/null and b/MarvelApp/Assets.xcassets/IronMan.imageset/iron-man-png-12.png differ diff --git a/MarvelApp/Assets.xcassets/Thor.colorset/Contents.json b/MarvelApp/Assets.xcassets/Thor.colorset/Contents.json new file mode 100644 index 0000000..6d3a4c0 --- /dev/null +++ b/MarvelApp/Assets.xcassets/Thor.colorset/Contents.json @@ -0,0 +1,38 @@ +{ + "colors" : [ + { + "color" : { + "color-space" : "srgb", + "components" : { + "alpha" : "1.000", + "blue" : "0.167", + "green" : "0.975", + "red" : "1.000" + } + }, + "idiom" : "universal" + }, + { + "appearances" : [ + { + "appearance" : "luminosity", + "value" : "dark" + } + ], + "color" : { + "color-space" : "srgb", + "components" : { + "alpha" : "1.000", + "blue" : "1.000", + "green" : "1.000", + "red" : "1.000" + } + }, + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/MarvelApp/Assets.xcassets/Thor.imageset/Contents.json b/MarvelApp/Assets.xcassets/Thor.imageset/Contents.json new file mode 100644 index 0000000..6df1c19 --- /dev/null +++ b/MarvelApp/Assets.xcassets/Thor.imageset/Contents.json @@ -0,0 +1,22 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x" + }, + { + "filename" : "fc318551acc519108d011018a0a33421.png", + "idiom" : "universal", + "scale" : "2x" + }, + { + "filename" : "fc318551acc519108d011018a0a33421-2.png", + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/MarvelApp/Assets.xcassets/Thor.imageset/fc318551acc519108d011018a0a33421-2.png b/MarvelApp/Assets.xcassets/Thor.imageset/fc318551acc519108d011018a0a33421-2.png new file mode 100644 index 0000000..aa406d3 Binary files /dev/null and b/MarvelApp/Assets.xcassets/Thor.imageset/fc318551acc519108d011018a0a33421-2.png differ diff --git a/MarvelApp/Assets.xcassets/Thor.imageset/fc318551acc519108d011018a0a33421.png b/MarvelApp/Assets.xcassets/Thor.imageset/fc318551acc519108d011018a0a33421.png new file mode 100644 index 0000000..aa406d3 Binary files /dev/null and b/MarvelApp/Assets.xcassets/Thor.imageset/fc318551acc519108d011018a0a33421.png differ diff --git a/MarvelApp/HeroData.swift b/MarvelApp/HeroData.swift new file mode 100644 index 0000000..7b2f80a --- /dev/null +++ b/MarvelApp/HeroData.swift @@ -0,0 +1,14 @@ + +import Foundation + +struct HeroData { + var asset: String + var name: String + var color: String +} + +let listHeroData: [HeroData] = [ HeroData(asset: "CaptainAmerica", name: "Captain America", color: "CaptainAmerica"), + HeroData(asset: "IronMan", name: "Iron Man", color: "IronMan"), + HeroData(asset: "Deadpool", name: "Deadpool", color: "Deadpool"), + HeroData(asset: "DoctorStrange", name: "Doctor Strange", color: "DoctorStrange"), + HeroData(asset: "Thor", name: "Thor", color: "Thor") ] diff --git a/MarvelApp/HeroesCardsView.swift b/MarvelApp/HeroesCardsView.swift deleted file mode 100644 index d2884a8..0000000 --- a/MarvelApp/HeroesCardsView.swift +++ /dev/null @@ -1,12 +0,0 @@ -// -// HeroesCardsView.swift -// MarvelApp -// -// Created by effective_macbook_pro on 21.02.2023. -// - -import UIKit - -class HeroesCardsView: UIView{ - -} diff --git a/MarvelApp/MyCell.swift b/MarvelApp/MyCell.swift index 0782df3..ff4f3bc 100644 --- a/MarvelApp/MyCell.swift +++ b/MarvelApp/MyCell.swift @@ -1,37 +1,77 @@ import UIKit import CollectionViewPagingLayout -class MyCell: UICollectionViewCell { +struct HeroCellModel { + var name: String + var image: UIImage +} + +final class HeroCell: UICollectionViewCell { + + func setupCell(model: HeroCellModel) { + heroImageView.image = model.image + label.text = model.name + } - // The card view that we apply transforms on - var card: UIView! + private lazy var heroImageView: UIImageView = { + let imageView = UIImageView(frame: self.frame) + imageView.translatesAutoresizingMaskIntoConstraints = false + imageView.contentMode = .scaleToFill + return imageView + }() + + private lazy var label: UILabel = { + let textView = UILabel() + textView.translatesAutoresizingMaskIntoConstraints = false + textView.backgroundColor = .clear + textView.textColor = .white + textView.font = UIFont.systemFont(ofSize: 30, weight: .bold) + return textView + }() + + private let view: UIView = { + let view = UIView() + view.translatesAutoresizingMaskIntoConstraints = false + view.backgroundColor = .black + view.layer.cornerRadius = 20 + return view + }() + override init(frame: CGRect) { - super.init(frame: frame) - setup() + super.init(frame: .zero) + + view.addSubview(heroImageView) + view.addSubview(label) + contentView.addSubview(view) + + NSLayoutConstraint.activate([ + view.topAnchor.constraint(equalTo: contentView.topAnchor), + view.bottomAnchor.constraint(equalTo: contentView.bottomAnchor, constant: -40), + view.rightAnchor.constraint(equalTo: contentView.rightAnchor, constant: -30), + view.leftAnchor.constraint(equalTo: contentView.leftAnchor, constant: 30) + ]) + NSLayoutConstraint.activate([ + label.topAnchor.constraint(equalTo: view.centerYAnchor, constant: 50), + label.heightAnchor.constraint(equalToConstant: 60), + label.leftAnchor.constraint(equalTo: view.leftAnchor, constant: 15), + label.rightAnchor.constraint(equalTo: view.rightAnchor, constant: -15) + ]) + NSLayoutConstraint.activate([ + heroImageView.topAnchor.constraint(equalTo: view.topAnchor, constant: 20), + heroImageView.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: -20), + heroImageView.leftAnchor.constraint(equalTo: view.leftAnchor, constant: 15), + heroImageView.rightAnchor.constraint(equalTo: view.rightAnchor, constant: -15) + ]) } required init?(coder: NSCoder) { super.init(coder: coder) - setup() } - func setup() { - // Adjust the card view frame - // you can use Auto-layout too - let cardFrame = CGRect( - x: 80, - y: 100, - width: frame.width - 160, - height: frame.height - 200 - ) - card = UIView(frame: cardFrame) - card.backgroundColor = .systemOrange - contentView.addSubview(card) - } } -extension MyCell: ScaleTransformView { +extension HeroCell: ScaleTransformView { var scaleOptions: ScaleTransformViewOptions { .layout(.linear) } diff --git a/MarvelApp/PathView.swift b/MarvelApp/PathView.swift new file mode 100644 index 0000000..0d73dd7 --- /dev/null +++ b/MarvelApp/PathView.swift @@ -0,0 +1,25 @@ +import UIKit + +final class PathView: UIView { + private let path = UIBezierPath() + var color: UIColor = .clear { + didSet { + setNeedsDisplay() + } + } + private func setupNewColor() { + color.setStroke() + path.stroke() + color.setFill() + path.fill() + } + override func draw(_ rect: CGRect) { + path.move(to: CGPoint(x: self.frame.minX, y: self.frame.maxY)) + path.addLine(to: CGPoint(x: self.frame.maxX, y: self.frame.maxY)) + path.addLine(to: CGPoint(x: self.frame.maxX, y: self.frame.midY)) + path.addLine(to: CGPoint(x: self.frame.minX, y: self.frame.maxY)) + path.close() + path.lineWidth = 3 + setupNewColor() + } +} diff --git a/MarvelApp/SceneDelegate.swift b/MarvelApp/SceneDelegate.swift index 5818fa2..d47e970 100644 --- a/MarvelApp/SceneDelegate.swift +++ b/MarvelApp/SceneDelegate.swift @@ -1,10 +1,3 @@ -// -// SceneDelegate.swift -// MarvelApp -// -// Created by effective_macbook_pro on 20.02.2023. -// - import UIKit class SceneDelegate: UIResponder, UIWindowSceneDelegate { diff --git a/MarvelApp/ViewController.swift b/MarvelApp/ViewController.swift index b57db83..0d99177 100644 --- a/MarvelApp/ViewController.swift +++ b/MarvelApp/ViewController.swift @@ -1,90 +1,130 @@ -// -// ViewController.swift -// MarvelApp -// -// Created by effective_macbook_pro on 20.02.2023. -// - import UIKit import CollectionViewPagingLayout -class ViewController: UIViewController, UICollectionViewDataSource { - var marvelLogoView: UIImageView! - var heroesCollectionView: UICollectionView! - var underLogoText: UITextView! - var backgroundColor = UIColor(named: "BackgroundColor") +class ViewController: UIViewController { - override func viewDidLoad() { - super.viewDidLoad() - } + private var lastCenterIndex = 0 + private var pathView: PathView = { + let pathView = PathView() + pathView.translatesAutoresizingMaskIntoConstraints = false + pathView.backgroundColor = .clear + pathView.color = UIColor(named: listHeroData[0].color)! + return pathView + }() + + private var logoImageView: UIImageView = { + let imageView = UIImageView() + imageView.backgroundColor = .clear + imageView.translatesAutoresizingMaskIntoConstraints = false + imageView.image = UIImage(named: "marvelLogo") + return imageView + }() - override func loadView() { + lazy var collectionView: UICollectionView = { + let layout = CollectionViewPagingLayout() + let collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout) + collectionView.translatesAutoresizingMaskIntoConstraints = false + collectionView.isPagingEnabled = true + collectionView.showsHorizontalScrollIndicator = false + collectionView.register(HeroCell.self, forCellWithReuseIdentifier: String(describing: HeroCell.self)) + collectionView.backgroundColor = .clear + collectionView.dataSource = self + collectionView.delegate = self + return collectionView + }() + + private var label: UILabel = { + let label = UILabel() + label.translatesAutoresizingMaskIntoConstraints = false + label.textColor = UIColor(named: "UnderLogoTextColor") + label.text = "Choose your hero" + label.textAlignment = .center + label.font = UIFont.systemFont(ofSize: 30, weight: .bold) + label.backgroundColor = .clear + return label + }() + + override func viewDidLoad() { + super.loadView() view = UIView() view.backgroundColor = UIColor(named: "BackgroundColor") - + setupViewLayout() + setupPath() setupMarvelLogo() setupUnderLogoText() setupHeroesCollection() + } + + private func setupViewLayout() { + view.addSubview(pathView) + view.addSubview(logoImageView) + view.addSubview(label) + view.addSubview(collectionView) + } + private func setupPath() { + NSLayoutConstraint.activate([ + pathView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor), + pathView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor), + pathView.leftAnchor.constraint(equalTo: view.leftAnchor), + pathView.rightAnchor.constraint(equalTo: view.rightAnchor) + ]) } private func setupMarvelLogo() { - marvelLogoView = UIImageView() - marvelLogoView.translatesAutoresizingMaskIntoConstraints = false - marvelLogoView.image = UIImage(named: "marvelLogo") - view.addSubview(marvelLogoView) - NSLayoutConstraint.activate([ - marvelLogoView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor), - marvelLogoView.centerXAnchor.constraint(equalTo: view.safeAreaLayoutGuide.centerXAnchor), - marvelLogoView.widthAnchor.constraint(equalToConstant: 200), - marvelLogoView.heightAnchor.constraint(equalToConstant: 75) + logoImageView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor), + logoImageView.centerXAnchor.constraint(equalTo: view.safeAreaLayoutGuide.centerXAnchor), + logoImageView.widthAnchor.constraint(equalToConstant: 100), + logoImageView.heightAnchor.constraint(equalToConstant: 25) ]) } + //TODO: Убрать константные ширину и высоту заменить на левый и правый constraint + private func setupUnderLogoText() { - underLogoText = UITextView() - underLogoText.translatesAutoresizingMaskIntoConstraints = false - underLogoText.textColor = UIColor(named: "UnderLogoTextColor") - underLogoText.text = "Choose your hero" - underLogoText.isUserInteractionEnabled = false - underLogoText.textAlignment = .center - underLogoText.font = UIFont.systemFont(ofSize: 30, weight: .bold) - underLogoText.backgroundColor = backgroundColor - view.addSubview(underLogoText) - NSLayoutConstraint.activate([ - underLogoText.topAnchor.constraint(equalTo: marvelLogoView.bottomAnchor), - underLogoText.centerXAnchor.constraint(equalTo: view.safeAreaLayoutGuide.centerXAnchor), - underLogoText.widthAnchor.constraint(equalToConstant: 400), - underLogoText.heightAnchor.constraint(equalToConstant: 75) + label.topAnchor.constraint(equalTo: logoImageView.bottomAnchor, constant: 20), + label.centerXAnchor.constraint(equalTo: view.safeAreaLayoutGuide.centerXAnchor), + label.widthAnchor.constraint(equalToConstant: 400), + label.heightAnchor.constraint(equalToConstant: 75) ]) } + //TODO: Убрать константные ширину и высоту заменить на левый и правый constraint private func setupHeroesCollection() { - let layout = CollectionViewPagingLayout() - heroesCollectionView = UICollectionView(frame: view.frame, collectionViewLayout: layout) - heroesCollectionView.translatesAutoresizingMaskIntoConstraints = false - heroesCollectionView.isPagingEnabled = true - heroesCollectionView.register(MyCell.self, forCellWithReuseIdentifier: "cell") - heroesCollectionView.backgroundColor = backgroundColor - heroesCollectionView.dataSource = self - view.addSubview(heroesCollectionView) - NSLayoutConstraint.activate([ - heroesCollectionView.topAnchor.constraint(equalTo: underLogoText.bottomAnchor), - heroesCollectionView.centerXAnchor.constraint(equalTo: view.safeAreaLayoutGuide.centerXAnchor), - heroesCollectionView.widthAnchor.constraint(equalTo: view.safeAreaLayoutGuide.widthAnchor), - heroesCollectionView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor) + collectionView.topAnchor.constraint(equalTo: label.bottomAnchor), + collectionView.centerXAnchor.constraint(equalTo: view.safeAreaLayoutGuide.centerXAnchor), + collectionView.widthAnchor.constraint(equalTo: view.safeAreaLayoutGuide.widthAnchor), + collectionView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor) ]) } - +} + +extension ViewController: UICollectionViewDataSource, UICollectionViewDelegate { func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { - 10 - } - + listHeroData.count + } + func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) - } + let cell = collectionView.dequeueReusableCell(withReuseIdentifier: String(describing: HeroCell.self), for: indexPath) as! HeroCell + + let hero = listHeroData[indexPath.item] + cell.setupCell(model: HeroCellModel(name: hero.name, image: UIImage(named: hero.asset)!)) + return cell + } + + func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) { + let centerIndex = findCenterIndex() + pathView.color = UIColor(named: listHeroData[centerIndex].color)! + } + + private func findCenterIndex() -> Int { + let center = self.view.convert(self.collectionView.center, to: self.collectionView) + let index = collectionView.indexPathForItem(at: center) + lastCenterIndex = index?.item ?? lastCenterIndex + return lastCenterIndex + } }