-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
✨ [FEAT] 홈 배너 UI 구현 #421
Merged
Merged
✨ [FEAT] 홈 배너 UI 구현 #421
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
98fd423
✅ Chore: BannerHeader, Titleheader BaseTVC 상속으로 변경 (#415)
dev-jungbin c4abfd7
➕ Add: HomeBannerTVC (#420)
dev-jungbin 120ec22
Merge remote-tracking branch 'origin' into feature/#420-Home-Banner-UI
dev-jungbin 2949099
➕ Add: Banner Paging icon image (#420)
dev-jungbin ca8e9b6
➕ Add: UIImageView+ setImageColor, setImageUrl 메서드 추가 (#420)
dev-jungbin 818ebe9
➕ Add: 이미지 캐시를 저장할 싱글톤 클래스 ImageCacheManager (#420)
dev-jungbin b948ffe
➕ Add: HomeBannerCVC (#420)
dev-jungbin 2f4df51
✅ Chore: HomeBannerTVC 연결 (#420)
dev-jungbin 37e07ee
✅ Chore: HomeVC TableView Cell Height 설정 (#420)
dev-jungbin 2188023
✅ Chore: Banner CV, CVFlowLayout 선언 (#420)
dev-jungbin 0754f41
✅ Chore: banner에 들어갈 image url 배열 선언 (#420)
dev-jungbin a531cac
✅ Chore: banner CV UI 코드 및 set 함수 작성 (#420)
dev-jungbin 42d340f
✨ Feat: 무한 페이징 적용, segmented control과 연결 (#420)
dev-jungbin 2e253d9
♻️ Refactor: UIPageControl로 리팩토링 (#420)
dev-jungbin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
NadoSunbae-iOS/NadoSunbae-iOS/Global/Extension/UIImageView+.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// | ||
// UIImageView+.swift | ||
// NadoSunbae | ||
// | ||
// Created by madilyn on 2022/08/06. | ||
// | ||
|
||
import UIKit | ||
|
||
extension UIImageView { | ||
|
||
/// 컬러만 있는 Image를 ImageView에 넣어 주는 메서드 | ||
func setImageColor(color: UIColor) { | ||
let templateImage = self.image?.withRenderingMode(.alwaysTemplate) | ||
self.image = templateImage | ||
self.tintColor = color | ||
} | ||
|
||
/// URL을 통해 이미지를 불러오는 메서드 + 캐싱 | ||
func setImageUrl(_ url: String) { | ||
let cacheKey = NSString(string: url) | ||
|
||
/// 해당 Key에 캐시 이미지가 저장되어 있으면 이미지 사용 | ||
if let cachedImage = ImageCacheManager.shared.object(forKey: cacheKey) { | ||
self.image = cachedImage | ||
return | ||
} | ||
|
||
DispatchQueue.global().async { | ||
if let url = URL(string: url) { | ||
let data = try? Data(contentsOf: url) | ||
DispatchQueue.main.async { | ||
if let data = data, let image = UIImage(data: data) { | ||
|
||
/// 다운받은 이미지를 캐시에 저장 | ||
ImageCacheManager.shared.setObject(image, forKey: cacheKey) | ||
self.image = image | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
NadoSunbae-iOS/NadoSunbae-iOS/Network/ImageCacheManager.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// | ||
// ImageCacheManager.swift | ||
// NadoSunbae | ||
// | ||
// Created by madilyn on 2022/08/06. | ||
// | ||
|
||
import UIKit | ||
|
||
/// 캐시를 저장해 놓을 싱글톤 클래스 | ||
class ImageCacheManager { | ||
static let shared = NSCache<NSString, UIImage>() | ||
private init() {} | ||
} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
NadoSunbae-iOS/NadoSunbae-iOS/Screen/Home/HomeBannerCVC.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// | ||
// HomeBannerCVC.swift | ||
// NadoSunbae | ||
// | ||
// Created by madilyn on 2022/08/06. | ||
// | ||
|
||
import UIKit | ||
import SnapKit | ||
import Then | ||
|
||
class HomeBannerCVC: BaseCVC { | ||
|
||
// MARK: Components | ||
private let imgView = UIImageView() | ||
|
||
// MARK: Initialization | ||
override init(frame: CGRect) { | ||
super.init(frame: frame) | ||
configureUI() | ||
} | ||
|
||
required init?(coder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
func setData(imageURL: String) { | ||
imgView.setImageUrl(imageURL) | ||
} | ||
} | ||
|
||
// MARK: - UI | ||
extension HomeBannerCVC { | ||
private func configureUI() { | ||
contentView.addSubviews([imgView]) | ||
|
||
imgView.snp.makeConstraints { | ||
$0.edges.equalToSuperview() | ||
} | ||
} | ||
} |
111 changes: 111 additions & 0 deletions
111
NadoSunbae-iOS/NadoSunbae-iOS/Screen/Home/TVC/HomeBannerTVC.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
// | ||
// HomeBannerTVC.swift | ||
// NadoSunbae | ||
// | ||
// Created by madilyn on 2022/08/06. | ||
// | ||
|
||
import UIKit | ||
import SnapKit | ||
import Then | ||
|
||
class HomeBannerTVC: BaseTVC { | ||
|
||
// MARK: Components | ||
private let bannerCV = UICollectionView(frame: .zero, collectionViewLayout: UICollectionViewLayout()).then { | ||
$0.showsHorizontalScrollIndicator = false | ||
$0.isPagingEnabled = true | ||
} | ||
private lazy var pageControl = UIPageControl().then { | ||
$0.pageIndicatorTintColor = .init(white: 1, alpha: 0.5) | ||
$0.currentPageIndicatorTintColor = .white | ||
$0.numberOfPages = bannerImaURLsData.count - 2 | ||
$0.isUserInteractionEnabled = false | ||
} | ||
|
||
// MARK: - Properties | ||
private lazy var CVFlowLayout = UICollectionViewFlowLayout().then { | ||
$0.scrollDirection = .horizontal | ||
$0.minimumLineSpacing = 0 | ||
$0.minimumInteritemSpacing = 0 | ||
$0.sectionInset = .zero | ||
$0.itemSize = CGSize.init(width: screenWidth, height: 104) | ||
} | ||
|
||
/// 첫 인덱스 -> 마지막 이미지, 마지막 인덱스 -> 첫 이미지 추가하기! | ||
private var bannerImaURLsData = ["https://user-images.githubusercontent.com/43312096/183249441-5ad2cffb-db34-421a-a23c-915415c0593a.png", "https://user-images.githubusercontent.com/43312096/183249428-0c5b531b-6290-40c3-80ec-2517c9c990f8.png", "https://user-images.githubusercontent.com/43312096/183249432-034f6b8b-5518-49ce-bd69-4e6f4764b071.png", "https://user-images.githubusercontent.com/43312096/183249433-17ae6687-1632-423b-929b-6c57ac51edf3.png", "https://user-images.githubusercontent.com/43312096/183249439-97333cf5-a88d-4d72-8dca-9641e4587260.png", "https://user-images.githubusercontent.com/43312096/183249441-5ad2cffb-db34-421a-a23c-915415c0593a.png", "https://user-images.githubusercontent.com/43312096/183249428-0c5b531b-6290-40c3-80ec-2517c9c990f8.png"] | ||
|
||
// MARK: - Initialization | ||
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { | ||
super.init(style: style, reuseIdentifier: reuseIdentifier) | ||
|
||
configureUI() | ||
setBannerCV() | ||
} | ||
|
||
required init?(coder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
private func setBannerCV() { | ||
bannerCV.dataSource = self | ||
bannerCV.delegate = self | ||
|
||
bannerCV.collectionViewLayout = CVFlowLayout | ||
bannerCV.register(HomeBannerCVC.self, forCellWithReuseIdentifier: HomeBannerCVC.className) | ||
|
||
DispatchQueue.main.async { | ||
self.bannerCV.scrollToItem(at: [0, 1], at: .left, animated: false) | ||
} | ||
} | ||
} | ||
|
||
// MARK: - UICollectionViewDataSource | ||
extension HomeBannerTVC: UICollectionViewDataSource, UICollectionViewDelegateFlowLayout { | ||
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { | ||
return bannerImaURLsData.count | ||
} | ||
|
||
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { | ||
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: HomeBannerCVC.className, for: indexPath) as? HomeBannerCVC else { return UICollectionViewCell() } | ||
cell.setData(imageURL: bannerImaURLsData[indexPath.row]) | ||
return cell | ||
} | ||
} | ||
|
||
// MARK: - UICollectionViewDelegate | ||
extension HomeBannerTVC: UICollectionViewDelegate { | ||
|
||
func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) { | ||
let pageFloat = (scrollView.contentOffset.x / scrollView.frame.size.width) | ||
let pageInt = Int(round(pageFloat)) | ||
|
||
switch pageInt { | ||
case 0: | ||
pageControl.currentPage = bannerImaURLsData.count - 3 | ||
bannerCV.scrollToItem(at: [0, bannerImaURLsData.count - 2], at: .left, animated: false) | ||
case bannerImaURLsData.count - 1: | ||
pageControl.currentPage = 0 | ||
bannerCV.scrollToItem(at: [0, 1], at: .left, animated: false) | ||
default: | ||
pageControl.currentPage = pageInt - 1 | ||
} | ||
} | ||
} | ||
|
||
// MARK: - UI | ||
extension HomeBannerTVC { | ||
private func configureUI() { | ||
contentView.addSubviews([bannerCV, pageControl]) | ||
|
||
bannerCV.snp.makeConstraints { | ||
$0.edges.equalToSuperview() | ||
} | ||
|
||
pageControl.snp.makeConstraints { | ||
$0.centerX.equalToSuperview() | ||
$0.bottom.equalToSuperview().inset(8) | ||
$0.height.equalTo(8) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
NadoSunbae-iOS/NadoSunbae-iOS/Support/Assets.xcassets/Home/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...S/NadoSunbae-iOS/Support/Assets.xcassets/Home/selectedSegmentImage.imageset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"filename" : "Ellipse 4.png", | ||
"idiom" : "universal", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"filename" : "Ellipse [email protected]", | ||
"idiom" : "universal", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"filename" : "Ellipse [email protected]", | ||
"idiom" : "universal", | ||
"scale" : "3x" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
}, | ||
"properties" : { | ||
"template-rendering-intent" : "original" | ||
} | ||
} |
Binary file added
BIN
+184 Bytes
...ae-iOS/Support/Assets.xcassets/Home/selectedSegmentImage.imageset/Ellipse 4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+263 Bytes
...iOS/Support/Assets.xcassets/Home/selectedSegmentImage.imageset/Ellipse [email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+325 Bytes
...iOS/Support/Assets.xcassets/Home/selectedSegmentImage.imageset/Ellipse [email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions
26
...NadoSunbae-iOS/Support/Assets.xcassets/Home/unselectedSegmentImage.imageset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"filename" : "Ellipse 4.png", | ||
"idiom" : "universal", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"filename" : "Ellipse [email protected]", | ||
"idiom" : "universal", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"filename" : "Ellipse [email protected]", | ||
"idiom" : "universal", | ||
"scale" : "3x" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
}, | ||
"properties" : { | ||
"template-rendering-intent" : "original" | ||
} | ||
} |
Binary file added
BIN
+210 Bytes
...-iOS/Support/Assets.xcassets/Home/unselectedSegmentImage.imageset/Ellipse 4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+277 Bytes
...S/Support/Assets.xcassets/Home/unselectedSegmentImage.imageset/Ellipse [email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+355 Bytes
...S/Support/Assets.xcassets/Home/unselectedSegmentImage.imageset/Ellipse [email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
머시따!!!