Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ struct UIOnboardingHelper {
title: "Enlist prepared",
description: "Practice with the app and pass the rank test on the first run."),
.init(icon: .init(named: "feature-3")!,
iconTint: .init(named: "camou") ?? UIColor.init(red: 0.654, green: 0.618, blue: 0.494, alpha: 1.0),
isPremium: true,
title: "#teamarmee",
description: "Add name tags of your comrades or cadre. Insignia automatically keeps every name tag you create in iCloud.")
])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@ import UIKit
struct UIOnboardingFeature {
var icon: UIImage!
var iconTint: UIColor
var isPremium: Bool
var premiumBadgeTitle: String
var title: String
var description: String
init(icon: UIImage!, iconTint: UIColor = .label, title: String, description: String) {

init(icon: UIImage!, iconTint: UIColor = .label, isPremium: Bool = false, premiumBadgeTitle: String = "Pro", title: String, description: String) {
self.icon = icon
self.iconTint = iconTint
self.isPremium = isPremium
self.premiumBadgeTitle = premiumBadgeTitle
self.title = title
self.description = description
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,56 @@ final class UIOnboardingCell: UITableViewCell {
set(feature)
}

private var premiumBadge: UIView?

private func set(_ feature: UIOnboardingFeature) {
premiumBadge?.removeFromSuperview()
premiumBadge = nil

featureGlyph.image = feature.icon
featureGlyph.tintColor = feature.iconTint

titleLabel.text = feature.title
titleLabel.accessibilityLabel = feature.title

descriptionLabel.text = feature.description
descriptionLabel.accessibilityLabel = feature.description

if feature.isPremium {
addPremiumBadge(tintColor: feature.iconTint, title: feature.premiumBadgeTitle)
}
}

private func addPremiumBadge(tintColor: UIColor, title: String) {

let label = UILabel()
label.text = title.uppercased()
label.font = .systemFont(ofSize: 8, weight: .heavy)
label.textColor = .white
label.textAlignment = .center

let badge = UIView()
badge.backgroundColor = tintColor
badge.layer.cornerRadius = 5
badge.clipsToBounds = true
badge.translatesAutoresizingMaskIntoConstraints = false
badge.addSubview(label)
label.translatesAutoresizingMaskIntoConstraints = false

NSLayoutConstraint.activate([
label.topAnchor.constraint(equalTo: badge.topAnchor, constant: 1),
label.bottomAnchor.constraint(equalTo: badge.bottomAnchor, constant: -1),
label.leadingAnchor.constraint(equalTo: badge.leadingAnchor, constant: 4),
label.trailingAnchor.constraint(equalTo: badge.trailingAnchor, constant: -4),
])

contentView.addSubview(badge)
NSLayoutConstraint.activate([
badge.trailingAnchor.constraint(equalTo: featureGlyph.trailingAnchor, constant: 4),
badge.bottomAnchor.constraint(equalTo: featureGlyph.bottomAnchor, constant: 2),
])

premiumBadge = badge
}

override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ struct UIOnboardingHelper {
title: "Enlist prepared",
description: "Practice with the app and pass the rank test on the first run."),
.init(icon: .init(named: "feature-3"),
iconTint: UIColor(named: "camou") ?? UIColor(red: 0.654, green: 0.618, blue: 0.494, alpha: 1.0),
isPremium: true,
title: "#teamarmee",
description: "Add name tags of your comrades or cadre. Insignia automatically keeps every name tag you create in iCloud.")
])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ struct UIOnboardingHelper {
title: "Enlist prepared",
description: "Practice with the app and pass the rank test on the first run."),
.init(icon: .init(named: "feature-3")!,
iconTint: .init(named: "camou") ?? UIColor.init(red: 0.654, green: 0.618, blue: 0.494, alpha: 1.0),
isPremium: true,
title: "#teamarmee",
description: "Add name tags of your comrades or cadre. Insignia automatically keeps every name tag you create in iCloud.")
])
Expand Down
8 changes: 6 additions & 2 deletions Sources/UIOnboarding/Configuration/UIOnboardingFeature.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@ import UIKit
public struct UIOnboardingFeature {
public var icon: UIImage
public var iconTint: UIColor
public var isPremium: Bool
public var premiumBadgeTitle: String
public var title: String
public var description: String
public init(icon: UIImage, iconTint: UIColor = .label, title: String, description: String) {

public init(icon: UIImage, iconTint: UIColor = .label, isPremium: Bool = false, premiumBadgeTitle: String = "Pro", title: String, description: String) {
self.icon = icon
self.iconTint = iconTint
self.isPremium = isPremium
self.premiumBadgeTitle = premiumBadgeTitle
self.title = title
self.description = description
}
Expand Down
45 changes: 43 additions & 2 deletions Sources/UIOnboarding/Views/UIOnboardingCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,56 @@ final class UIOnboardingCell: UITableViewCell {
set(feature)
}

private var premiumBadge: UIView?

private func set(_ feature: UIOnboardingFeature) {
premiumBadge?.removeFromSuperview()
premiumBadge = nil

featureGlyph.image = feature.icon
featureGlyph.tintColor = feature.iconTint

titleLabel.text = feature.title
titleLabel.accessibilityLabel = feature.title

descriptionLabel.text = feature.description
descriptionLabel.accessibilityLabel = feature.description

if feature.isPremium {
addPremiumBadge(tintColor: feature.iconTint, title: feature.premiumBadgeTitle)
}
}

private func addPremiumBadge(tintColor: UIColor, title: String) {

let label = UILabel()
label.text = title.uppercased()
label.font = .systemFont(ofSize: 8, weight: .heavy)
label.textColor = .white
label.textAlignment = .center

let badge = UIView()
badge.backgroundColor = tintColor
badge.layer.cornerRadius = 5
badge.clipsToBounds = true
badge.translatesAutoresizingMaskIntoConstraints = false
badge.addSubview(label)
label.translatesAutoresizingMaskIntoConstraints = false

NSLayoutConstraint.activate([
label.topAnchor.constraint(equalTo: badge.topAnchor, constant: 1),
label.bottomAnchor.constraint(equalTo: badge.bottomAnchor, constant: -1),
label.leadingAnchor.constraint(equalTo: badge.leadingAnchor, constant: 4),
label.trailingAnchor.constraint(equalTo: badge.trailingAnchor, constant: -4),
])

contentView.addSubview(badge)
NSLayoutConstraint.activate([
badge.trailingAnchor.constraint(equalTo: featureGlyph.trailingAnchor, constant: 4),
badge.bottomAnchor.constraint(equalTo: featureGlyph.bottomAnchor, constant: 2),
])

premiumBadge = badge
}

override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
Expand Down