diff --git a/HackIllinois/UI/HILabel.swift b/HackIllinois/UI/HILabel.swift index 90f7eb63..676cb09e 100644 --- a/HackIllinois/UI/HILabel.swift +++ b/HackIllinois/UI/HILabel.swift @@ -7,7 +7,7 @@ // This file is part of the Hackillinois iOS App. // The Hackillinois iOS App is open source software, released under the University of // Illinois/NCSA Open Source License. You should have received a copy of -// this license in a file with the distribution. +// this license in a file with the distribution. // import Foundation @@ -307,6 +307,7 @@ class HILabel: UILabel { case .leaderboardName: textHIColor = \.leaderboardText backgroundHIColor = \.clear + lineBreakMode = .byTruncatingTail if UIDevice.current.userInterfaceIdiom == .pad { font = HIAppearance.Font.leaderboardNamePad } else { diff --git a/HackIllinois/UI/TableView/Cells/HILeaderboardCell.swift b/HackIllinois/UI/TableView/Cells/HILeaderboardCell.swift index daf8c0e1..6ff7b973 100644 --- a/HackIllinois/UI/TableView/Cells/HILeaderboardCell.swift +++ b/HackIllinois/UI/TableView/Cells/HILeaderboardCell.swift @@ -20,6 +20,15 @@ class HILeaderboardCell: UITableViewCell { let nameLabel = HILabel(style: .leaderboardName) let rankLabel = HILabel(style: .leaderboardRank) let pointsLabel = HILabel(style: .leaderboardPoints) + + // iOS 16 TableView did not respect separator inset for + // first and last rows, add managed equivalent + let separatorView: UIView = { + let separatorView = UIView() + separatorView.backgroundColor = #colorLiteral(red: 0.04009541315, green: 0.1307413591, blue: 0.3802352191, alpha: 1) + separatorView.translatesAutoresizingMaskIntoConstraints = false + return separatorView + }() var cellView = HIView { $0.clipsToBounds = true @@ -33,10 +42,19 @@ class HILeaderboardCell: UITableViewCell { selectionStyle = .none backgroundColor = UIColor.clear contentView.addSubview(cellView) - cellView.constrain(to: safeAreaLayoutGuide, topInset: 0, trailingInset: 0, bottomInset: 0, leadingInset: 0) + + cellView.constrain( + to: safeAreaLayoutGuide, + topInset: 0, + trailingInset: -HILeaderboardCell.padding.right, + bottomInset: 0, + leadingInset: HILeaderboardCell.padding.left + ) + cellView.addSubview(rankLabel) cellView.addSubview(pointsLabel) cellView.addSubview(nameLabel) + cellView.addSubview(separatorView) } required init?(coder aDecoder: NSCoder) { @@ -44,6 +62,14 @@ class HILeaderboardCell: UITableViewCell { } } +// MARK: - Padding +extension HILeaderboardCell { + static var padding: UIEdgeInsets { + let pad = (UIScreen.main.bounds.width * 0.15) / 2.0 + return UIEdgeInsets(top: 0, left: pad, bottom: 0, right: pad) + } +} + // MARK: - Population extension HILeaderboardCell { static func heightForCell(with group: LeaderboardProfile, width: CGFloat) -> CGFloat { @@ -51,9 +77,9 @@ extension HILeaderboardCell { } static func <- (lhs: HILeaderboardCell, rhs: LeaderboardProfile) { - var padConstant = 1.0 + var padConstant = 25.0 if UIDevice.current.userInterfaceIdiom == .pad { - padConstant = 2.0 + padConstant = 50.0 } lhs.rankLabel.textAlignment = .center lhs.pointsLabel.textAlignment = .center @@ -67,23 +93,23 @@ extension HILeaderboardCell { lhs.nameLabel.textAlignment = .left lhs.rankLabel.centerYAnchor.constraint(equalTo: lhs.cellView.centerYAnchor).isActive = true - lhs.rankLabel.leadingAnchor.constraint(equalTo: lhs.cellView.leadingAnchor, constant: 25 * padConstant).isActive = true - lhs.rankLabel.setContentHuggingPriority(.defaultHigh, for: .horizontal) - + lhs.rankLabel.leadingAnchor.constraint(equalTo: lhs.cellView.leadingAnchor, constant: padConstant).isActive = true + lhs.rankLabel.widthAnchor.constraint(equalToConstant: 30).isActive = true + lhs.pointsLabel.centerYAnchor.constraint(equalTo: lhs.cellView.centerYAnchor).isActive = true lhs.pointsLabel.widthAnchor.constraint(equalTo: lhs.cellView.widthAnchor, multiplier: 0.24).isActive = true lhs.pointsLabel.trailingAnchor.constraint(equalTo: lhs.cellView.trailingAnchor, constant: -25).isActive = true lhs.pointsLabel.heightAnchor.constraint(equalTo: lhs.cellView.heightAnchor, multiplier: 0.38).isActive = true lhs.nameLabel.centerYAnchor.constraint(equalTo: lhs.cellView.centerYAnchor).isActive = true - lhs.nameLabel.leadingAnchor.constraint(equalTo: lhs.rankLabel.leadingAnchor, constant: 50 * padConstant).isActive = true + lhs.nameLabel.leadingAnchor.constraint(equalTo: lhs.rankLabel.trailingAnchor, constant: padConstant).isActive = true + lhs.nameLabel.trailingAnchor.constraint(equalTo: lhs.pointsLabel.leadingAnchor, constant: -10).isActive = true + lhs.nameLabel.numberOfLines = 1 - if UIDevice.current.userInterfaceIdiom == .pad { - lhs.nameLabel.constrain(width: lhs.contentView.frame.width, height: 40.0) - } else { - lhs.nameLabel.constrain(width: lhs.contentView.frame.width - 185, height: 20.0) - lhs.nameLabel.numberOfLines = 1 - } + lhs.separatorView.leadingAnchor.constraint(equalTo: lhs.cellView.leadingAnchor).isActive = true + lhs.separatorView.trailingAnchor.constraint(equalTo: lhs.cellView.trailingAnchor).isActive = true + lhs.separatorView.bottomAnchor.constraint(equalTo: lhs.cellView.bottomAnchor).isActive = true + lhs.separatorView.heightAnchor.constraint(equalToConstant: 1/UIScreen.main.scale).isActive = true } } diff --git a/HackIllinois/ViewControllers/HILeaderboardListViewController.swift b/HackIllinois/ViewControllers/HILeaderboardListViewController.swift index 20c06fa5..0f87a86f 100644 --- a/HackIllinois/ViewControllers/HILeaderboardListViewController.swift +++ b/HackIllinois/ViewControllers/HILeaderboardListViewController.swift @@ -16,6 +16,7 @@ import HIAPI import APIManager class HILeaderboardListViewController: HIBaseViewController { + } // MARK: - UITableView Setup @@ -24,6 +25,7 @@ extension HILeaderboardListViewController { if let tableView = tableView { tableView.register(HILeaderboardCell.self, forCellReuseIdentifier: HILeaderboardCell.identifier) } + super.setupTableView() } } @@ -36,19 +38,22 @@ extension HILeaderboardListViewController { cell <- leaderboardProfile cell.indexPath = indexPath cell.rankLabel.text = "\((indexPath.row) + 1)" - cell.backgroundColor = #colorLiteral(red: 0.7882352941, green: 0.8235294118, blue: 0.8980392157, alpha: 1) - tableView.separatorStyle = .singleLine - tableView.separatorInset = UIEdgeInsets() - tableView.separatorColor = #colorLiteral(red: 0.04009541315, green: 0.1307413591, blue: 0.3802352191, alpha: 1) + cell.backgroundColor = .clear + + cell.cellView.backgroundColor = #colorLiteral(red: 0.7882352941, green: 0.8235294118, blue: 0.8980392157, alpha: 1) + // Round certain corners based on row if indexPath.row == 0 { - cell.layer.cornerRadius = 20 - cell.layer.maskedCorners = [.layerMinXMinYCorner, .layerMaxXMinYCorner] + cell.cellView.layer.cornerRadius = 20 + cell.cellView.layer.maskedCorners = [.layerMinXMinYCorner, .layerMaxXMinYCorner] + cell.separatorView.isHidden = false } else if indexPath.row == 9 { - cell.layer.cornerRadius = 20 - cell.layer.maskedCorners = [.layerMinXMaxYCorner, .layerMaxXMaxYCorner] + cell.cellView.layer.cornerRadius = 20 + cell.cellView.layer.maskedCorners = [.layerMinXMaxYCorner, .layerMaxXMaxYCorner] + cell.separatorView.isHidden = true } else { - cell.layer.cornerRadius = 0 + cell.cellView.layer.cornerRadius = 0 + cell.separatorView.isHidden = false } } diff --git a/HackIllinois/ViewControllers/HILeaderboardViewController.swift b/HackIllinois/ViewControllers/HILeaderboardViewController.swift index e9550e03..7d0e4a59 100644 --- a/HackIllinois/ViewControllers/HILeaderboardViewController.swift +++ b/HackIllinois/ViewControllers/HILeaderboardViewController.swift @@ -78,7 +78,7 @@ extension HILeaderboardViewController { tableView.layer.cornerRadius = 8 tableView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 15 * padConstant).isActive = true tableView.heightAnchor.constraint(equalTo: view.safeAreaLayoutGuide.heightAnchor, multiplier: 0.90).isActive = true - tableView.widthAnchor.constraint(equalTo: view.safeAreaLayoutGuide.widthAnchor, multiplier: 0.85).isActive = true + tableView.widthAnchor.constraint(equalTo: view.safeAreaLayoutGuide.widthAnchor, multiplier: 1).isActive = true tableView.centerXAnchor.constraint(equalTo: view.safeAreaLayoutGuide.centerXAnchor).isActive = true self.tableView = tableView }