-
Notifications
You must be signed in to change notification settings - Fork 149
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
만국박람회 [Step 2] Gray, Danny #310
base: ic_11_danny
Are you sure you want to change the base?
Changes from all commits
b78c7e1
541e8b0
82faa63
0183545
e4eecca
2b81bd7
0148ed9
6a53e53
158da01
93c513e
b95b8dd
ae1cb0c
263236a
2880e99
69d98d6
6dda91d
66afc25
96e53c7
08d6ddb
a15fef9
4012e1d
4242b26
79af818
50d5929
4efdc39
56f640c
31c0509
ca54ea4
6135f67
bbcb6f5
36ca741
aa703ad
df1e0a4
b577685
923644b
fcd3d9c
a485893
626b8c1
7185445
f63df9b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,215 @@ | ||
// | ||
// ExpositionViewController.swift | ||
// Expo1900 | ||
// | ||
// Created by Danny, Gray on 3/13/24. | ||
// | ||
|
||
import UIKit | ||
|
||
class ExpositionViewController: UIViewController { | ||
var expositionIntroduction: ExpositionIntroduction! | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 강제 언래핑(!)은 없는 기능이라고 생각해주세요. |
||
|
||
private var mainTitleLabel: UILabel = { | ||
let label = UILabel() | ||
label.font = UIFont.preferredFont(forTextStyle: .title1) | ||
return label | ||
}() | ||
|
||
private var subTitleLabel: UILabel = { | ||
let label = UILabel() | ||
label.font = UIFont.preferredFont(forTextStyle: .title2) | ||
return label | ||
}() | ||
|
||
private var posterImageView: UIImageView = { | ||
let imageView = UIImageView() | ||
return imageView | ||
}() | ||
Comment on lines
+25
to
+28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 따로 무언가 속성을 바꾸지 않는다면, 클로저로 initialize안하고 바로 해도 괜찮을거 같아요! |
||
|
||
private var visitorLabel: UILabel = { | ||
let label = UILabel() | ||
return label | ||
}() | ||
|
||
private var locationLabel: UILabel = { | ||
let label = UILabel() | ||
return label | ||
}() | ||
|
||
private var durationLabel: UILabel = { | ||
let label = UILabel() | ||
return label | ||
}() | ||
|
||
private var descriptionLabel: UILabel = { | ||
let label = UILabel() | ||
return label | ||
}() | ||
Comment on lines
+13
to
+48
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let이어도 되지 않을까요?
|
||
|
||
private let contentScrollView: UIScrollView = { | ||
let scrollView = UIScrollView() | ||
scrollView.translatesAutoresizingMaskIntoConstraints = false | ||
scrollView.showsHorizontalScrollIndicator = false | ||
return scrollView | ||
}() | ||
|
||
private let contentView: UIView = { | ||
let view = UIView() | ||
view.translatesAutoresizingMaskIntoConstraints = false | ||
return view | ||
}() | ||
|
||
private let expositionIntroductionStackView: UIStackView = { | ||
let stackView = UIStackView() | ||
stackView.translatesAutoresizingMaskIntoConstraints = false | ||
stackView.axis = .vertical | ||
stackView.alignment = .center | ||
stackView.distribution = .equalSpacing | ||
stackView.spacing = 8 | ||
return stackView | ||
}() | ||
|
||
private let buttonStackView: UIStackView = { | ||
let stackView = UIStackView() | ||
stackView.translatesAutoresizingMaskIntoConstraints = false | ||
stackView.axis = .horizontal | ||
stackView.alignment = .fill | ||
stackView.distribution = .fill | ||
stackView.spacing = 8 | ||
return stackView | ||
}() | ||
|
||
private let koreanFlagImageViewFirst: UIImageView = { | ||
let imageView = UIImageView() | ||
imageView.image = UIImage(named: "flag") | ||
return imageView | ||
}() | ||
|
||
private let koreanFlagImageViewSecond: UIImageView = { | ||
let imageView = UIImageView() | ||
imageView.image = UIImage(named: "flag") | ||
return imageView | ||
}() | ||
|
||
private let koreanHeritageButton: UIButton = { | ||
let button = UIButton(type: .system) | ||
button.setTitle("한국 출품작 보러가기", for: .normal) | ||
return button | ||
}() | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
expositionIntroductionJsonDecode() | ||
showExpositionIntroduction() | ||
addSubview() | ||
} | ||
|
||
override func viewWillAppear(_ animated: Bool) { | ||
navigationController?.navigationBar.isHidden = true | ||
} | ||
|
||
override func viewWillDisappear(_ animated: Bool) { | ||
navigationController?.navigationBar.isHidden = false | ||
} | ||
} | ||
|
||
extension ExpositionViewController { | ||
private func expositionIntroductionJsonDecode(){ | ||
let jsonDecoder: JSONDecoder = JSONDecoder() | ||
guard let dataAsset: NSDataAsset = NSDataAsset(name: "exposition_universelle_1900") else { | ||
return | ||
} | ||
|
||
do { | ||
self.expositionIntroduction = try jsonDecoder.decode(ExpositionIntroduction.self, from: dataAsset.data) | ||
} catch { | ||
print(error.localizedDescription) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 에러처리도 요구사항중에 중요한 부분이라고 생각되는데요, |
||
} | ||
} | ||
} | ||
|
||
extension ExpositionViewController { | ||
private func addSubview() { | ||
view.addSubview(contentScrollView) | ||
contentScrollView.addSubview(contentView) | ||
contentView.addSubview(expositionIntroductionStackView) | ||
expositionIntroductionStackView.addArrangedSubview(mainTitleLabel) | ||
expositionIntroductionStackView.addArrangedSubview(subTitleLabel) | ||
expositionIntroductionStackView.addArrangedSubview(posterImageView) | ||
expositionIntroductionStackView.addArrangedSubview(visitorLabel) | ||
expositionIntroductionStackView.addArrangedSubview(locationLabel) | ||
expositionIntroductionStackView.addArrangedSubview(durationLabel) | ||
expositionIntroductionStackView.addArrangedSubview(descriptionLabel) | ||
expositionIntroductionStackView.addArrangedSubview(buttonStackView) | ||
buttonStackView.addArrangedSubview(koreanFlagImageViewFirst) | ||
buttonStackView.addArrangedSubview(koreanHeritageButton) | ||
buttonStackView.addArrangedSubview(koreanFlagImageViewSecond) | ||
Comment on lines
+137
to
+147
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. stackView에 넣을 때 setCustomSpacing이었나 따로 스페이싱 주는 인터페이스가 있으니 참고하심 좋을듯~ |
||
|
||
setUpUIConstraints() | ||
} | ||
|
||
private func setUpUIConstraints() { | ||
NSLayoutConstraint.activate([ | ||
contentScrollView.topAnchor.constraint(equalTo: view.topAnchor), | ||
contentScrollView.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor), | ||
contentScrollView.bottomAnchor.constraint(equalTo: view.bottomAnchor), | ||
contentScrollView.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor), | ||
|
||
contentView.topAnchor.constraint(equalTo: contentScrollView.topAnchor), | ||
contentView.leadingAnchor.constraint(equalTo: contentScrollView.leadingAnchor), | ||
contentView.bottomAnchor.constraint(equalTo: contentScrollView.bottomAnchor), | ||
contentView.trailingAnchor.constraint(equalTo: contentScrollView.trailingAnchor), | ||
contentView.widthAnchor.constraint(equalTo: contentScrollView.widthAnchor), | ||
|
||
expositionIntroductionStackView.topAnchor.constraint(equalTo: contentView.topAnchor), | ||
expositionIntroductionStackView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: 20), | ||
expositionIntroductionStackView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -20), | ||
expositionIntroductionStackView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor, constant: -20), | ||
|
||
buttonStackView.heightAnchor.constraint(equalToConstant: 50), | ||
|
||
koreanFlagImageViewFirst.widthAnchor.constraint(equalTo: buttonStackView.widthAnchor, multiplier: 0.2), | ||
koreanFlagImageViewSecond.widthAnchor.constraint(equalTo: buttonStackView.widthAnchor, multiplier: 0.2) | ||
]) | ||
|
||
} | ||
} | ||
|
||
extension ExpositionViewController { | ||
private func showExpositionIntroduction(){ | ||
let numberFormatter: NumberFormatter = NumberFormatter() | ||
numberFormatter.numberStyle = .decimal | ||
|
||
guard let visitorString: String = numberFormatter.string(for: expositionIntroduction.visitors) else { | ||
return | ||
} | ||
|
||
mainTitleLabel.text = String(expositionIntroduction.title.prefix(13)) | ||
subTitleLabel.text = String(expositionIntroduction.title.suffix(28)) | ||
Comment on lines
+188
to
+189
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 요 로직은 조금 의아한데요, title이 41글자가 아니면 에러가 날수도 있을거 같아요! |
||
posterImageView.image = UIImage(named: "poster.png") | ||
visitorLabel.attributedText = textAttributedToString(text: "방문객 : \(visitorString) 명", length: 3) | ||
locationLabel.attributedText = textAttributedToString(text: "개최지 : \(expositionIntroduction.location)", length: 3) | ||
durationLabel.attributedText = textAttributedToString(text: "개최 기간 : \(expositionIntroduction.duration)", length: 6) | ||
descriptionLabel.numberOfLines = 0 | ||
descriptionLabel.text = expositionIntroduction.description | ||
koreanHeritageButton.addTarget(self, action: #selector(openKoreanHeritageViewController), for: .touchUpInside) | ||
} | ||
|
||
private func textAttributedToString(text: String, length: Int) -> NSAttributedString { | ||
let textAttributes:[NSAttributedString.Key: Any] = [.font: UIFont.systemFont(ofSize: 20)] | ||
let textAttributedToString = NSMutableAttributedString(string: text) | ||
textAttributedToString.addAttributes(textAttributes, range: NSRange(location: 0, length: length)) | ||
return textAttributedToString | ||
} | ||
|
||
@objc private func openKoreanHeritageViewController() { | ||
let koreanHeritageViewController = KoreanHeritageViewController() | ||
let backBarButtonItem = UIBarButtonItem(title: "메인", style: .plain, target: self, action: nil) | ||
self.navigationItem.backBarButtonItem = backBarButtonItem | ||
koreanHeritageViewController.title = "한국의 출품작" | ||
|
||
navigationController?.pushViewController(koreanHeritageViewController, animated: true) | ||
} | ||
} | ||
|
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.
static dispatch를 위해서 final은 디폴트로 붙여주세용