-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
170 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
SWDestinyTrades/Classes/CardDetail/View/DieSymbolView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// | ||
// DieSymbolView.swift | ||
// SWDestinyTrades | ||
// | ||
// Created by Diogo Autilio on 08/09/22. | ||
// Copyright © 2022 Diogo Autilio. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import UIKit | ||
|
||
final class DieSymbolView: UIStackView { | ||
|
||
var quantity: UILabel = { | ||
let label = UILabel(frame: .zero) | ||
label.font = .boldSystemFont(ofSize: 20) | ||
label.textAlignment = .center | ||
label.textColor = .black | ||
label.setContentHuggingPriority(.defaultHigh, for: .horizontal) | ||
label.adjustsFontSizeToFitWidth = true | ||
return label | ||
}() | ||
|
||
var symbol: UIImageView = { | ||
let imageView = UIImageView(frame: .zero) | ||
imageView.contentMode = .scaleAspectFit | ||
return imageView | ||
}() | ||
|
||
init(face: String) { | ||
super.init(frame: .zero) | ||
axis = .horizontal | ||
distribution = .fillEqually | ||
alignment = .center | ||
buildViewHierarchy() | ||
setupConstraints() | ||
configureViews() | ||
configureDie(face: face) | ||
} | ||
|
||
@available(*, unavailable) | ||
required init(coder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
internal func configureDie(face: String) {} | ||
} | ||
|
||
extension DieSymbolView: BaseViewConfiguration { | ||
|
||
internal func buildViewHierarchy() { | ||
addArrangedSubview(quantity) | ||
addArrangedSubview(symbol) | ||
} | ||
|
||
internal func setupConstraints() { | ||
// faceContainer.layout.applyConstraint { make in | ||
// make.topAnchor(equalTo: topAnchor) | ||
// make.leadingAnchor(equalTo: leadingAnchor) | ||
// make.bottomAnchor(equalTo: bottomAnchor) | ||
// make.trailingAnchor(equalTo: trailingAnchor) | ||
// } | ||
// | ||
// stackView.layout.applyConstraint { make in | ||
// make.topAnchor(equalTo: faceContainer.topAnchor) | ||
// make.leadingAnchor(equalTo: faceContainer.leadingAnchor, constant: 8) | ||
// make.bottomAnchor(equalTo: faceContainer.bottomAnchor) | ||
// make.trailingAnchor(equalTo: faceContainer.trailingAnchor, constant: -8) | ||
// } | ||
|
||
symbol.layout.applyConstraint { make in | ||
make.heightAnchor(equalToConstant: 25) | ||
make.widthAnchor(equalToConstant: 25) | ||
} | ||
} | ||
|
||
internal func configureViews() { | ||
backgroundColor = .clear | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// | ||
// Regex.swift | ||
// SWDestinyTrades | ||
// | ||
// Created by Diogo Autilio on 19/08/22. | ||
// Copyright © 2022 Diogo Autilio. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
struct Regex { | ||
|
||
let pattern: String | ||
let options: NSRegularExpression.Options | ||
|
||
private var matcher: NSRegularExpression { | ||
return try! NSRegularExpression(pattern: pattern, options: options) // swiftlint:disable:this force_try | ||
} | ||
|
||
init(pattern: String, options: NSRegularExpression.Options = []) { | ||
self.pattern = pattern | ||
self.options = options | ||
} | ||
|
||
func match(_ string: String, options: NSRegularExpression.MatchingOptions = []) -> Bool { | ||
return matcher.numberOfMatches(in: string, options: options, range: NSRange(location: 0, length: string.utf16.count)) != 0 | ||
} | ||
} | ||
|
||
protocol RegularExpressionMatchable { | ||
func match(_ regex: Regex) -> Bool | ||
} | ||
|
||
extension String: RegularExpressionMatchable { | ||
|
||
func match(_ regex: Regex) -> Bool { | ||
return regex.match(self) | ||
} | ||
} | ||
|
||
func ~= <T: RegularExpressionMatchable>(pattern: Regex, matchable: T) -> Bool { | ||
return matchable.match(pattern) | ||
} |