Skip to content

Commit

Permalink
FInalise leaderboard
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanessamae23 committed Apr 10, 2024
1 parent 38238ec commit 41cb394
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
<!--Leaderboard Selection View Controller-->
<scene sceneID="SlJ-QI-6Dh">
<objects>
<tabBarController storyboardIdentifier="LeaderboardSelectionViewController" modalPresentationStyle="fullScreen" useStoryboardIdentifierAsRestorationIdentifier="YES" id="22d-FP-2g3" customClass="LeaderboardSelectionViewController" customModule="TowerForge" customModuleProvider="target" sceneMemberID="viewController">
<tabBarController storyboardIdentifier="LeaderboardSelectionViewController" extendedLayoutIncludesOpaqueBars="YES" modalPresentationStyle="fullScreen" useStoryboardIdentifierAsRestorationIdentifier="YES" id="22d-FP-2g3" customClass="LeaderboardSelectionViewController" customModule="TowerForge" customModuleProvider="target" sceneMemberID="viewController">
<navigationItem key="navigationItem" id="LUD-kC-ATN"/>
<tabBar key="tabBar" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" id="ecM-56-JFJ">
<rect key="frame" x="0.0" y="0.0" width="393" height="49"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ class LeaderboardViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()
setupScrollView()
setupViews()

fetchTopRanks(type: self.type.rawValue)
}

Expand All @@ -52,12 +54,48 @@ class LeaderboardViewController: UIViewController {
self.displayLeaderboard(ranks: result)
}
}
private let scrollView: UIScrollView = {
let scrollView = UIScrollView()
scrollView.translatesAutoresizingMaskIntoConstraints = false
return scrollView
}()

private func setupScrollView() {
view.addSubview(scrollView)
scrollView.addSubview(stackView)

NSLayoutConstraint.activate([
scrollView.topAnchor.constraint(equalTo: view.topAnchor, constant: 20),
scrollView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 20),
scrollView.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -20),
scrollView.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: -20),

stackView.topAnchor.constraint(equalTo: scrollView.topAnchor),
stackView.leadingAnchor.constraint(equalTo: scrollView.leadingAnchor),
stackView.trailingAnchor.constraint(equalTo: scrollView.trailingAnchor),
stackView.bottomAnchor.constraint(equalTo: scrollView.bottomAnchor),
stackView.widthAnchor.constraint(equalTo: scrollView.widthAnchor)
])
}

private func displayLeaderboard(ranks: [GameRankData]) {
for rankData in ranks {
let rankLabel = UILabel()

if let customFont = UIFont(name: "Nosifer-Regular", size: 24) {
rankLabel.font = customFont
}

rankLabel.text = "\(rankData.username): \(rankData.score)"
rankLabel.textColor = .white

rankLabel.backgroundColor = .gray
rankLabel.layer.cornerRadius = 8
rankLabel.layer.masksToBounds = true
rankLabel.textAlignment = .center
rankLabel.layoutMargins = UIEdgeInsets(top: 10.0, left: 10.0, bottom: 10.0, right: 10.0)

rankLabel.translatesAutoresizingMaskIntoConstraints = false
stackView.addArrangedSubview(rankLabel)
}
}
Expand Down

0 comments on commit 41cb394

Please sign in to comment.