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

Add SwiftUI Label #474

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions HackIllinois.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@
BF0FDA3925F4DCCD003B5DB1 /* HIScheduleSegmentedControl.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF0FDA3825F4DCCD003B5DB1 /* HIScheduleSegmentedControl.swift */; };
BFB1FD3E26105EA400500008 /* HIEditProfileCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFB1FD3D26105EA400500008 /* HIEditProfileCell.swift */; };
D3A309BC2211175200CBA351 /* PassKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D3A309BB2211175200CBA351 /* PassKit.framework */; };
E1E4A5DD291C9F3F00780BA1 /* HILabelSUI.swift in Sources */ = {isa = PBXBuildFile; fileRef = E1E4A5DC291C9F3F00780BA1 /* HILabelSUI.swift */; };
E1E4A5D9291C9BF800780BA1 /* HICarouselSwiftUIView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E1E4A5D6291C9BF700780BA1 /* HICarouselSwiftUIView.swift */; };
E1E4A5DA291C9BF800780BA1 /* HIOnboardingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E1E4A5D7291C9BF700780BA1 /* HIOnboardingView.swift */; };
E1E4A5DB291C9BF800780BA1 /* HIOnboardingViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = E1E4A5D8291C9BF700780BA1 /* HIOnboardingViewModel.swift */; };
Expand Down Expand Up @@ -309,6 +310,7 @@
BFB1FD3D26105EA400500008 /* HIEditProfileCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HIEditProfileCell.swift; sourceTree = "<group>"; };
D3A309BA221116A600CBA351 /* HackIllinois.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = HackIllinois.entitlements; sourceTree = "<group>"; };
D3A309BB2211175200CBA351 /* PassKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = PassKit.framework; path = System/Library/Frameworks/PassKit.framework; sourceTree = SDKROOT; };
E1E4A5DC291C9F3F00780BA1 /* HILabelSUI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HILabelSUI.swift; sourceTree = "<group>"; };
E1E4A5D6291C9BF700780BA1 /* HICarouselSwiftUIView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HICarouselSwiftUIView.swift; sourceTree = "<group>"; };
E1E4A5D7291C9BF700780BA1 /* HIOnboardingView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HIOnboardingView.swift; sourceTree = "<group>"; };
E1E4A5D8291C9BF700780BA1 /* HIOnboardingViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HIOnboardingViewModel.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -532,6 +534,7 @@
ACAA7177260186EF000F42B0 /* CollectionView */,
95FC79BD21E0199600715036 /* HIAppearance.swift */,
95A7D27B203D4F54005EAEAF /* HIButton.swift */,
E1E4A5DC291C9F3F00780BA1 /* HILabelSUI.swift */,
9523A28F2218BA2600341EBD /* HIImageView.swift */,
95A7D29D203D5BA4005EAEAF /* HILabel.swift */,
95A7D27C203D4F54005EAEAF /* HISegmentedControl.swift */,
Expand Down Expand Up @@ -907,6 +910,7 @@
95CA9230201E60D300C46037 /* UIImage+QRCode.swift in Sources */,
AC3B621325E86053002386A2 /* Profile+CoreDataClass.swift in Sources */,
95A7D2A0203D60E9005EAEAF /* HIBubbleCell.swift in Sources */,
E1E4A5DD291C9F3F00780BA1 /* HILabelSUI.swift in Sources */,
9552D92821758E4C00A8C869 /* UIView+AutoLayout.swift in Sources */,
ACB53AED261B8ACD007B1643 /* HIInterestDataSource.swift in Sources */,
083C643327A7457000087018 /* HIHomeSegmentedControl.swift in Sources */,
Expand Down
269 changes: 269 additions & 0 deletions HackIllinois/UI/HILabelSUI.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,269 @@
//
// HILabelSUI.swift
// HackIllinois
//
// Created by Vincent Nguyen on 11/9/22.
// Copyright © 2022 HackIllinois. All rights reserved.
//

import SwiftUI

struct HILabelSUI: View {
// MARK: - Properties
let labelText: String
let textHIColor: HIColor
let font: UIFont?
let backgroundHIColor: HIColor
var textAlignment: TextAlignment = .leading
var borderWidth: CGFloat = 0
var borderColor: Color = .clear
// MARK: - Init
init(labelText: String, style: Style) {
self.labelText = labelText
switch style {

case .location:
self.textHIColor = \.baseText
backgroundHIColor = \.clear
font = HIAppearance.Font.contentText

case .event:
textHIColor = \.baseText
backgroundHIColor = \.clear
font = HIAppearance.Font.eventTitle

case .eventTime:
textHIColor = \.baseText
backgroundHIColor = \.clear
font = HIAppearance.Font.eventTime

case .eventType:
textHIColor = \.baseText
backgroundHIColor = \.clear
font = HIAppearance.Font.eventCategoryText

case .sponsor:
textHIColor = \.baseText
backgroundHIColor = \.clear
font = HIAppearance.Font.sponsorText

case .detailTitle:
textHIColor = \.baseText
backgroundHIColor = \.clear
font = HIAppearance.Font.detailTitle

case .detailSubtitle:
textHIColor = \.baseText
backgroundHIColor = \.clear
font = HIAppearance.Font.detailSubtitle

case .detailText:
textHIColor = \.baseText
backgroundHIColor = \.clear
font = HIAppearance.Font.detailText

case .project:
textHIColor = \.baseText
backgroundHIColor = \.clear
font = HIAppearance.Font.contentTitle

case .viewTitle:
textHIColor = \.baseText
backgroundHIColor = \.clear
textAlignment = .center
font = HIAppearance.Font.viewTitle

case .subtitle:
textHIColor = \.accent
backgroundHIColor = \.clear
font = HIAppearance.Font.contentSubtitle

case .description:
textHIColor = \.baseText
backgroundHIColor = \.clear
font = HIAppearance.Font.descriptionText

case .cellDescription:
textHIColor = \.baseText
backgroundHIColor = \.clear
font = HIAppearance.Font.eventDetails

case .loginHeader:
textHIColor = \.loginTitleBackground
backgroundHIColor = \.clear
font = HIAppearance.Font.loginTitle

case .welcomeTitle:
textHIColor = \.loginSelectionText
backgroundHIColor = \.clear
font = HIAppearance.Font.loginTitle

case .backgroundTitle:
textHIColor = \.baseText
backgroundHIColor = \.clear
textAlignment = .center
font = HIAppearance.Font.navigationSubtitle

case .loginSelection:
textHIColor = \.loginSelectionText
backgroundHIColor = \.clear
textAlignment = .center
font = HIAppearance.Font.loginSelection
// borderWidth = 2.0
// borderColor = Color((\HIAppearance.loginSelectionText).value.cgColor)

case .profileName: // Used to display the profile owner's name
textHIColor = \.baseText
backgroundHIColor = \.clear
textAlignment = .center
font = HIAppearance.Font.profileName

case .profileSubtitle: // Used to display profile subtitle, "points", and whatever that says "time zone"
backgroundHIColor = \.clear
textHIColor = \.baseText
textAlignment = .center
font = HIAppearance.Font.profileSubtitle

case .profileNumberFigure: // Used to display number of points and time (?)
textHIColor = \.baseText
backgroundHIColor = \.clear
textAlignment = .center
font = HIAppearance.Font.profileNumberFigure

case .profileTier: // Used to display "short description"
textHIColor = \.baseText
backgroundHIColor = \.clear
textAlignment = .leading
font = HIAppearance.Font.profileTier

case .profileUsername: // Used to display Discord username, etc.
textHIColor = \.whiteTagFont
backgroundHIColor = \.clear
textAlignment = .leading
font = HIAppearance.Font.profileUsername

case .profileInterests:
textHIColor = \.whiteTagFont
backgroundHIColor = \.clear
textAlignment = .center
font = HIAppearance.Font.profileInterests

case .navigationInfo:
textHIColor = \.titleText
backgroundHIColor = \.clear
font = HIAppearance.Font.navigationInfoText
textAlignment = .leading

case .countdown:
textHIColor = \.titleText
backgroundHIColor = \.clear
font = HIAppearance.Font.countdownText

case .pointsText:
textHIColor = \.baseText
backgroundHIColor = \.clear
font = HIAppearance.Font.eventButtonText
textAlignment = .center

case .error:
textHIColor = \.baseText
backgroundHIColor = \.clear
font = HIAppearance.Font.detailSubtitle
textAlignment = .center

case .codeError:
textHIColor = \.baseText
backgroundHIColor = \.clear
font = HIAppearance.Font.detailSubtitle
textAlignment = .center

case .onboardingDescription:
textHIColor = \.baseText
backgroundHIColor = \.clear
font = HIAppearance.Font.onboardingDescription
textAlignment = .center

case .onboardingTitle:
textHIColor = \.baseText
backgroundHIColor = \.clear
font = HIAppearance.Font.onboardingTitle
textAlignment = .center

case .clock:
textHIColor = \.baseText
backgroundHIColor = \.clear
font = HIAppearance.Font.clockText
textAlignment = .center

// Leaderboard label fonts
case .leaderboardRank:
textHIColor = \.leaderboardText
backgroundHIColor = \.clear
font = HIAppearance.Font.leaderboardRank
//layer.shadowOffset = CGSize(width: 2, height: 2)
//layer.shadowRadius = 2.0
//layer.shadowOpacity = 0.25
case .leaderboardName:
textHIColor = \.leaderboardText
backgroundHIColor = \.clear
font = HIAppearance.Font.leaderboardPoints
case .leaderboardPoints:
textHIColor = \.leaderboardText
backgroundHIColor = \.pointsBackground
font = HIAppearance.Font.leaderboardPoints
}

}
var body: some View {
Text(labelText)
.foregroundColor(Color(textHIColor.value))
.background(Color(backgroundHIColor.value))
.font(Font(font!))
.multilineTextAlignment(textAlignment)
.border(borderColor, width: borderWidth)
}

// MARK: - Types
enum Style {
case location
case event
case eventTime
case eventType
case sponsor
case project
case viewTitle
case detailTitle
case subtitle
case description
case cellDescription
case loginHeader
case loginSelection
case welcomeTitle
case backgroundTitle
case detailSubtitle
case detailText
case profileName
case profileSubtitle
case profileNumberFigure
case profileTier
case profileUsername
case profileInterests
case navigationInfo
case countdown
case pointsText
case error
case codeError
case onboardingDescription
case onboardingTitle
case clock
case leaderboardRank
case leaderboardName
case leaderboardPoints
}
}

struct HILabelSUI_Previews: PreviewProvider {
static var previews: some View {
HILabelSUI(labelText: "HELLO", style: .loginSelection)
}
}