Skip to content
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

박스오피스II [STEP 2] Jusbug, Redmango #107

Open
wants to merge 12 commits into
base: ic_9_jusbug2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .DS_Store
Binary file not shown.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.DS_Store
*.xcuserstate

APIKey.plist
APIKey.plist
BoxOffice.xcodeproj/xcuserdata/redmango1446.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
20 changes: 20 additions & 0 deletions BoxOffice.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
objects = {

/* Begin PBXBuildFile section */
5D2CF6C92A8B6F0A009EECB3 /* CollectionViewIconCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5D2CF6C72A8B6F0A009EECB3 /* CollectionViewIconCell.swift */; };
5D2CF6CA2A8B6F0A009EECB3 /* CollectionViewIconCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 5D2CF6C82A8B6F0A009EECB3 /* CollectionViewIconCell.xib */; };
5D4FAA982A6E8604001FA74A /* BoxOfficeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5D4FAA972A6E8604001FA74A /* BoxOfficeTests.swift */; };
5D4FAAA12A6E88D3001FA74A /* box_office_sample.json in Resources */ = {isa = PBXBuildFile; fileRef = 5D4FAAA02A6E88D2001FA74A /* box_office_sample.json */; };
5DDFC3282A72628700135954 /* Movie.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5DDFC3272A72628700135954 /* Movie.swift */; };
Expand All @@ -29,6 +31,7 @@
D0989F712A77616400716556 /* APIError.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0989F702A77616400716556 /* APIError.swift */; };
D0989F882A7B517900716556 /* APIKey.plist in Resources */ = {isa = PBXBuildFile; fileRef = D0989F872A7B517900716556 /* APIKey.plist */; };
D0989F8A2A7B522400716556 /* HideAPIKey++Bundle.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0989F892A7B522400716556 /* HideAPIKey++Bundle.swift */; };
D0F060152A8C96DF006133E4 /* Arrow.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0F060142A8C96DF006133E4 /* Arrow.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand All @@ -42,6 +45,8 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
5D2CF6C72A8B6F0A009EECB3 /* CollectionViewIconCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CollectionViewIconCell.swift; sourceTree = "<group>"; };
5D2CF6C82A8B6F0A009EECB3 /* CollectionViewIconCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = CollectionViewIconCell.xib; sourceTree = "<group>"; };
5D4FAA952A6E8604001FA74A /* BoxOfficeTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = BoxOfficeTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
5D4FAA972A6E8604001FA74A /* BoxOfficeTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BoxOfficeTests.swift; sourceTree = "<group>"; };
5D4FAAA02A6E88D2001FA74A /* box_office_sample.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = box_office_sample.json; sourceTree = "<group>"; };
Expand All @@ -67,6 +72,7 @@
D0989F702A77616400716556 /* APIError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = APIError.swift; sourceTree = "<group>"; };
D0989F872A7B517900716556 /* APIKey.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = APIKey.plist; sourceTree = "<group>"; };
D0989F892A7B522400716556 /* HideAPIKey++Bundle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "HideAPIKey++Bundle.swift"; sourceTree = "<group>"; };
D0F060142A8C96DF006133E4 /* Arrow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Arrow.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -193,6 +199,7 @@
children = (
63DF20F42970E1A0005DF7D1 /* Main.storyboard */,
5DDFC35A2A79FBEB00135954 /* CollectionViewListCell.xib */,
5D2CF6C82A8B6F0A009EECB3 /* CollectionViewIconCell.xib */,
63DF20F92970E1A1005DF7D1 /* LaunchScreen.storyboard */,
);
path = View;
Expand All @@ -214,14 +221,24 @@
D06DF27F2A6E737D0074F9EF /* Controller */ = {
isa = PBXGroup;
children = (
D0F060162A8C9782006133E4 /* Enum */,
D0246A132A81E4B70045C0B6 /* Protocol+ */,
63DF20F22970E1A0005DF7D1 /* MainViewController.swift */,
D0246A0F2A81DDC50045C0B6 /* CalendarViewController.swift */,
5DDFC3592A79FBEB00135954 /* CollectionViewListCell.swift */,
5D2CF6C72A8B6F0A009EECB3 /* CollectionViewIconCell.swift */,
);
path = Controller;
sourceTree = "<group>";
};
D0F060162A8C9782006133E4 /* Enum */ = {
isa = PBXGroup;
children = (
D0F060142A8C96DF006133E4 /* Arrow.swift */,
);
path = Enum;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -311,6 +328,7 @@
buildActionMask = 2147483647;
files = (
63DF20FB2970E1A1005DF7D1 /* LaunchScreen.storyboard in Resources */,
5D2CF6CA2A8B6F0A009EECB3 /* CollectionViewIconCell.xib in Resources */,
63DF20F82970E1A1005DF7D1 /* Assets.xcassets in Resources */,
63DF20F62970E1A0005DF7D1 /* Main.storyboard in Resources */,
D0989F882A7B517900716556 /* APIKey.plist in Resources */,
Expand Down Expand Up @@ -341,11 +359,13 @@
5DDFC38E2A83881500135954 /* DateProviderError.swift in Sources */,
5DDFC3282A72628700135954 /* Movie.swift in Sources */,
5DDFC35E2A7A61A400135954 /* DateProvider.swift in Sources */,
5D2CF6C92A8B6F0A009EECB3 /* CollectionViewIconCell.swift in Sources */,
5DDFC32A2A735C0100135954 /* URLManager.swift in Sources */,
D040BE3D2A713E86007F2095 /* APIManager.swift in Sources */,
D06DF2812A6E73B40074F9EF /* BoxOffice.swift in Sources */,
D0246A102A81DDC50045C0B6 /* CalendarViewController.swift in Sources */,
63DF20F32970E1A0005DF7D1 /* MainViewController.swift in Sources */,
D0F060152A8C96DF006133E4 /* Arrow.swift in Sources */,
63DF20EF2970E1A0005DF7D1 /* AppDelegate.swift in Sources */,
D0989F712A77616400716556 /* APIError.swift in Sources */,
63DF20F12970E1A0005DF7D1 /* SceneDelegate.swift in Sources */,
Expand Down

This file was deleted.

89 changes: 89 additions & 0 deletions BoxOffice/Controller/CollectionViewIconCell.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
//
// CollectionViewIconCell.swift
// BoxOffice
//
// Created by redmango1446 on 2023/08/15.
//

import UIKit

class CollectionViewIconCell: UICollectionViewCell {
@IBOutlet weak var rankNumberLabel: UILabel!
@IBOutlet weak var movieNameLabel: UILabel!
@IBOutlet weak var rankInfoLabel: UILabel!
@IBOutlet weak var audiNumberLabel: UILabel!
Comment on lines +11 to +14

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

외부에서 접근하는 경우가 있을까요~?

나머지 프로퍼티들도 한 번씩 더 고민 해 보셔도 좋을듯합니다 :)


override func awakeFromNib() {
super.awakeFromNib()

}

override func layoutSubviews() {
super.layoutSubviews()
self.layer.borderWidth = 1
self.layer.borderColor = UIColor.black.cgColor
self.layer.cornerRadius = 10
}
Comment on lines +21 to +26

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

요 함수는 언제 호출될까요?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • layoutSubview():하위 뷰들의 레이아웃이 조정되는 시점에 호출
  • viewWillLayoutSubview(): 하위 뷰의 레이아웃이 조정되기 직전에 호출
  • viewDIdLayoutSubview(): 하위 뷰의 레이아웃이 조정된 후에 호출


func configureFont() {
rankNumberLabel.font = .preferredFont(forTextStyle: .title1)
rankInfoLabel.font = .preferredFont(forTextStyle: .body)
audiNumberLabel.font = .preferredFont(forTextStyle: .body)
audiNumberLabel.adjustsFontSizeToFitWidth = true
movieNameLabel.font = .preferredFont(forTextStyle: .title3)
movieNameLabel.allowsDefaultTighteningForTruncation = true
movieNameLabel.numberOfLines = 2
}

func configureDynamicType() {
rankNumberLabel.adjustsFontForContentSizeCategory = true
rankInfoLabel.adjustsFontForContentSizeCategory = true
movieNameLabel.adjustsFontForContentSizeCategory = true
audiNumberLabel.adjustsFontForContentSizeCategory = true
}

func configureLabels(with dailyBoxOffice: DailyBoxOffice) {
configureAudiNumberLabel(with: dailyBoxOffice)
configureRankInfoLabel(with: dailyBoxOffice)
rankNumberLabel.text = dailyBoxOffice.rank
movieNameLabel.text = dailyBoxOffice.movieName
}

func configureAudiNumberLabel(with dailyBoxOffice: DailyBoxOffice) {
let numberFormatter = NumberFormatter()
numberFormatter.numberStyle = .decimal

guard let audiCnt = Int(dailyBoxOffice.audiCnt),
let formattedAudiCnt = numberFormatter.string(from: NSNumber(value: audiCnt)) else { return }

guard let audiAcc = Int(dailyBoxOffice.audiAcc),
let formattedAudiAcc = numberFormatter.string(from: NSNumber(value: audiAcc)) else { return }

audiNumberLabel.text = "오늘 \(formattedAudiCnt) / 총 \(formattedAudiAcc)"
}

func configureRankInfoLabel(with dailyBoxOffice: DailyBoxOffice) {
switch dailyBoxOffice.rankOldAndNew {
case "NEW":
rankInfoLabel.textColor = .red
rankInfoLabel.text = "신작"
case "OLD":
if dailyBoxOffice.rankInten == "0" {
rankInfoLabel.text = "-"
return
}

if let rankInten = Int(dailyBoxOffice.rankInten),
let arrow = Arrow(rawValue: rankInten) {
rankInfoLabel.textColor = .black
let rankIntenString = "\(arrow.rawValue)\(abs(rankInten))"
let attributedString = NSMutableAttributedString(string: rankIntenString)
let range = (rankIntenString as NSString).range(of: arrow.rawValue)
attributedString.addAttribute(.foregroundColor, value: arrow.color, range: range)
rankInfoLabel.attributedText = attributedString
}
default:
print("no Data")
}
}
}
36 changes: 12 additions & 24 deletions BoxOffice/Controller/CollectionViewListCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,17 @@ final class CollectionViewListCell: UICollectionViewListCell {
}

func configureFont() {
rankNumberLabel.font = UIFont.systemFont(ofSize: 30)
rankInfoLabel.font = UIFont.systemFont(ofSize: 15)
audiNumberLabel.font = UIFont.systemFont(ofSize: 15)
rankNumberLabel.font = .preferredFont(forTextStyle: .title1)
rankInfoLabel.font = .preferredFont(forTextStyle: .caption1)
movieNameLabel.font = .preferredFont(forTextStyle: .title3)
audiNumberLabel.font = .preferredFont(forTextStyle: .caption1)
}

func configureDynamicType() {
rankNumberLabel.adjustsFontForContentSizeCategory = true
rankInfoLabel.adjustsFontForContentSizeCategory = true
movieNameLabel.adjustsFontForContentSizeCategory = true
audiNumberLabel.adjustsFontForContentSizeCategory = true
}

func configureLabels(with dailyBoxOffice: DailyBoxOffice) {
Expand Down Expand Up @@ -50,6 +58,7 @@ final class CollectionViewListCell: UICollectionViewListCell {
rankInfoLabel.text = "신작"
case "OLD":
if dailyBoxOffice.rankInten == "0" {
rankInfoLabel.textColor = .black
rankInfoLabel.text = "-"
return
}
Expand All @@ -68,24 +77,3 @@ final class CollectionViewListCell: UICollectionViewListCell {
}
}
}

extension CollectionViewListCell {
enum Arrow: String {
case upArrow = "▲"
case downArrow = "▼"

var color: UIColor {
switch self {
case .upArrow:
return .red
case .downArrow:
return .blue
}
}

init?(rawValue: Int) {
self = rawValue > 0 ? .upArrow : .downArrow
}
}
}

26 changes: 26 additions & 0 deletions BoxOffice/Controller/Enum/Arrow.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// Arrow.swift
// BoxOffice
//
// Created by 박종화 on 2023/08/16.
//

import UIKit

enum Arrow: String {
case upArrow = "▲"
case downArrow = "▼"

var color: UIColor {
switch self {
case .upArrow:
return .red
case .downArrow:
return .blue
}
}

init?(rawValue: Int) {
self = rawValue > 0 ? .upArrow : .downArrow
}
Comment on lines +23 to +25

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

실패하는 경우가 있을까요~?

}
Loading