refactored label and textfields
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
7664b1e05a
commit
5c3e6b0ea5
@ -38,7 +38,7 @@ public class TextField: UITextField {
|
|||||||
public func setup() {
|
public func setup() {
|
||||||
keyboardType = .alphabet
|
keyboardType = .alphabet
|
||||||
returnKeyType = .done
|
returnKeyType = .done
|
||||||
|
autocorrectionType = .no
|
||||||
resigner = publisher(for: .editingDidEndOnExit)
|
resigner = publisher(for: .editingDidEndOnExit)
|
||||||
.sink { [weak self] _ in
|
.sink { [weak self] _ in
|
||||||
self?.shouldResign()
|
self?.shouldResign()
|
||||||
@ -79,19 +79,7 @@ public class NumericField: TextField {
|
|||||||
|
|
||||||
public override func setup() {
|
public override func setup() {
|
||||||
super.setup()
|
super.setup()
|
||||||
let keypadToolbar: UIToolbar = UIToolbar().with { $0.tintColor = .white; $0.backgroundColor = .white }
|
keyboardType = .numbersAndPunctuation
|
||||||
|
|
||||||
// add a done button to the numberpad
|
|
||||||
keypadToolbar.items=[
|
|
||||||
UIBarButtonItem(barButtonSystemItem: UIBarButtonItem.SystemItem.flexibleSpace, target: self, action: nil),
|
|
||||||
UIBarButtonItem(title: " - (minus sign)", style: .done, target: self, action: #selector(insertMinus)).with { $0.tintColor = .black},
|
|
||||||
UIBarButtonItem(title: "Done", style: UIBarButtonItem.Style.done, target: self, action: #selector(shouldResign)).with { $0.tintColor = .black}
|
|
||||||
]
|
|
||||||
keypadToolbar.sizeToFit()
|
|
||||||
|
|
||||||
// add a toolbar with a done button above the number pad
|
|
||||||
inputAccessoryView = keypadToolbar
|
|
||||||
keyboardType = .decimalPad
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc public func insertMinus() {
|
@objc public func insertMinus() {
|
||||||
|
|||||||
@ -31,6 +31,8 @@ class LabelViewController: BaseViewController<Label> {
|
|||||||
//testing only remove later
|
//testing only remove later
|
||||||
//------------------------------------
|
//------------------------------------
|
||||||
var useMinimumLineHeight = Toggle().with { $0.isOn = NSMutableAttributedString.useMinimumLineHeight }
|
var useMinimumLineHeight = Toggle().with { $0.isOn = NSMutableAttributedString.useMinimumLineHeight }
|
||||||
|
var useScaledLineHeight = Toggle().with { $0.isOn = NSMutableAttributedString.useScaledLineHeight }
|
||||||
|
|
||||||
var pointSizeRange = Slider().with {
|
var pointSizeRange = Slider().with {
|
||||||
$0.minimumValue = 5
|
$0.minimumValue = 5
|
||||||
$0.value = 0
|
$0.value = 0
|
||||||
@ -49,35 +51,66 @@ class LabelViewController: BaseViewController<Label> {
|
|||||||
}
|
}
|
||||||
//------------------------------------
|
//------------------------------------
|
||||||
var scaledMode: Bool { component.useScaledFont && TextStyle.canScaleFonts }
|
var scaledMode: Bool { component.useScaledFont && TextStyle.canScaleFonts }
|
||||||
var baseStyle: TextStyle!
|
var baseStyle: TextStyle! {
|
||||||
|
didSet {
|
||||||
|
baseStyleLabel.text = descriptionFor(style: baseStyle)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func descriptionFor(style: TextStyle) -> String {
|
||||||
|
var scaledFont = style.font.scaledFont
|
||||||
|
var customizedDesc: String = "Name: \(style.rawValue) \nFont Face-Weight: \(style.font.fontName)"
|
||||||
|
customizedDesc += "\nVDS LetterSpacing: \(style.letterSpacing)"
|
||||||
|
if scaledMode {
|
||||||
|
customizedDesc += "\nVDS PointSize: \(style.pointSize.rounded())"
|
||||||
|
customizedDesc += "\n* iOS PointSize: \(scaledFont.pointSize.rounded())"
|
||||||
|
} else {
|
||||||
|
customizedDesc += "\n* VDS PointSize: \(style.pointSize.rounded())"
|
||||||
|
}
|
||||||
|
if scaledMode {
|
||||||
|
if useScaledLineHeight.isOn {
|
||||||
|
customizedDesc += "\nVDS LineHeight: \(style.lineHeight)"
|
||||||
|
customizedDesc += "\n* VDS Ratio LineHeight: \(style.scaledLineHeight)"
|
||||||
|
} else {
|
||||||
|
customizedDesc += "\n* VDS LineHeight: \(style.lineHeight)"
|
||||||
|
}
|
||||||
|
customizedDesc += "\niOS LineHeight: \(scaledFont.lineHeight.rounded())"
|
||||||
|
} else {
|
||||||
|
customizedDesc += "\n* VDS LineHeight: \(style.lineHeight)"
|
||||||
|
customizedDesc += "\niOS LineHeight: \(style.font.lineHeight.rounded())"
|
||||||
|
}
|
||||||
|
return customizedDesc
|
||||||
|
}
|
||||||
|
|
||||||
var currentStyle: TextStyle! {
|
var currentStyle: TextStyle! {
|
||||||
didSet {
|
didSet {
|
||||||
//--------------------------------------------------------------
|
//--------------------------------------------------------------
|
||||||
#warning("testing only remove later")
|
#warning("testing only remove later")
|
||||||
//--------------------------------------------------------------
|
//--------------------------------------------------------------
|
||||||
let lineheight = scaledMode ? currentStyle.scaledLineHeight : currentStyle.lineHeight
|
pointSizeRange.value = Float(currentStyle.pointSize.rounded())
|
||||||
let lineheightText = scaledMode ? "\(baseStyle.lineHeight.rounded()) sc\(currentStyle.scaledLineHeight)" : "\(baseStyle.lineHeight.rounded())"
|
|
||||||
|
|
||||||
pointSizeRange.value = Float(currentStyle.pointSize)
|
|
||||||
pointSizeRange.maximumValue = Float(baseStyle.pointSize * 1.50)
|
pointSizeRange.maximumValue = Float(baseStyle.pointSize * 1.50)
|
||||||
lineheightRange.value = Float(lineheight)
|
lineheightRange.value = Float(currentStyle.lineHeight.rounded())
|
||||||
lineheightRange.maximumValue = Float((scaledMode ? baseStyle.scaledLineHeight : lineheight) * 1.50)
|
lineheightRange.maximumValue = Float(pointSizeRange.value * 1.50)
|
||||||
lineheightRange.minimumValue = 1
|
lineheightRange.minimumValue = 1
|
||||||
|
|
||||||
topInsetRange.value = Float(currentStyle.edgeInsets.top)
|
topInsetRange.value = Float(currentStyle.edgeInsets.top).rounded()
|
||||||
bottomInsetRange.value = Float(currentStyle.edgeInsets.bottom)
|
bottomInsetRange.value = Float(currentStyle.edgeInsets.bottom).rounded()
|
||||||
defaultLineHeightLabel?.text = "Line Height - iOS:\(Int(currentFont.lineHeight.rounded())) VDS:\(lineheightText)"
|
updateStyleLabel()
|
||||||
let text = scaledMode ? "iOS: \(Int(currentFont.pointSize.rounded()))" : ""
|
|
||||||
defaultPointLabel?.text = "Font Size - \(text) VDS:\(currentStyle.pointSize.rounded())"
|
|
||||||
//--------------------------------------------------------------
|
//--------------------------------------------------------------
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var useScaledFont = Toggle()
|
var useScaledFont = Toggle()
|
||||||
var boldSwitch = Toggle()
|
var boldSwitch = Toggle()
|
||||||
var disabledSwitch = Toggle()
|
var disabledSwitch = Toggle()
|
||||||
var textField = TextField()
|
var textField = TextField()
|
||||||
private var isBold: Bool = false
|
private var isBold: Bool = false
|
||||||
|
|
||||||
|
fileprivate func updateStyleLabel() {
|
||||||
|
baseStyleLabel.text = descriptionFor(style: baseStyle)
|
||||||
|
currentStyleLabel.text = descriptionFor(style: currentStyle)
|
||||||
|
}
|
||||||
|
|
||||||
override func setup() {
|
override func setup() {
|
||||||
super.setup()
|
super.setup()
|
||||||
|
|
||||||
@ -94,13 +127,15 @@ class LabelViewController: BaseViewController<Label> {
|
|||||||
setupPicker()
|
setupPicker()
|
||||||
setupModel()
|
setupModel()
|
||||||
}
|
}
|
||||||
var defaultLineHeightLabel: Label?
|
var calculatedLabel = Label()
|
||||||
var defaultPointLabel: Label?
|
var baseStyleLabel = Label()
|
||||||
var calculatedLabel = UILabel()
|
|
||||||
var scaledFontRow: UIView?
|
var scaledFontRow: UIView?
|
||||||
|
var scaledLineHeightRow: UIView?
|
||||||
|
var currentStyleRow: UIView?
|
||||||
|
var currentStyleLabel = Label()
|
||||||
func checkForScaledFonts() {
|
func checkForScaledFonts() {
|
||||||
scaledFontRow?.isHidden = !TextStyle.canScaleFonts
|
scaledFontRow?.isHidden = !TextStyle.canScaleFonts
|
||||||
|
scaledLineHeightRow?.isHidden = !TextStyle.canScaleFonts
|
||||||
updateLabelStyle()
|
updateLabelStyle()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,6 +147,7 @@ class LabelViewController: BaseViewController<Label> {
|
|||||||
|
|
||||||
//Scaled Fonts implementation
|
//Scaled Fonts implementation
|
||||||
scaledFontRow = addFormRow(label: "Use Scaled Font", view: useScaledFont)
|
scaledFontRow = addFormRow(label: "Use Scaled Font", view: useScaledFont)
|
||||||
|
scaledLineHeightRow = addFormRow(label: "Use Scaled LineHeight", view: useScaledLineHeight)
|
||||||
checkForScaledFonts()
|
checkForScaledFonts()
|
||||||
|
|
||||||
addFormRow(label: "Text Position", view: textPositionPickerSelectorView)
|
addFormRow(label: "Text Position", view: textPositionPickerSelectorView)
|
||||||
@ -148,14 +184,14 @@ class LabelViewController: BaseViewController<Label> {
|
|||||||
//--------------------------------------------------------------
|
//--------------------------------------------------------------
|
||||||
let testingSection = FormSection()
|
let testingSection = FormSection()
|
||||||
testingSection.title = "Temporary Settings"
|
testingSection.title = "Temporary Settings"
|
||||||
testingSection.addFormRow(label: "Calculated", view: calculatedLabel)
|
testingSection.addFormRow(label: "Original Style Props", view: baseStyleLabel)
|
||||||
|
currentStyleRow = testingSection.addFormRow(label: "Customized Style Props", view: currentStyleLabel)
|
||||||
testingSection.addFormRow(label: "Min LineHeight", view: useMinimumLineHeight)
|
testingSection.addFormRow(label: "Min LineHeight", view: useMinimumLineHeight)
|
||||||
let pointView = testingSection.addFormRow(label: "Font Size", view: pointSizeRange)
|
testingSection.addFormRow(label: "Calculated", view: calculatedLabel)
|
||||||
let view = testingSection.addFormRow(label: "Line Height", view: lineheightRange)
|
testingSection.addFormRow(label: "Point Size", view: pointSizeRange)
|
||||||
|
testingSection.addFormRow(label: "Line Height", view: lineheightRange)
|
||||||
testingSection.addFormRow(label: "Top Inset", view: topInsetRange)
|
testingSection.addFormRow(label: "Top Inset", view: topInsetRange)
|
||||||
testingSection.addFormRow(label: "Bottom Inset", view: bottomInsetRange)
|
testingSection.addFormRow(label: "Bottom Inset", view: bottomInsetRange)
|
||||||
defaultLineHeightLabel = view.viewWithTag(1) as? Label
|
|
||||||
defaultPointLabel = pointView.viewWithTag(1) as? Label
|
|
||||||
append(section: testingSection)
|
append(section: testingSection)
|
||||||
|
|
||||||
useMinimumLineHeight
|
useMinimumLineHeight
|
||||||
@ -163,6 +199,15 @@ class LabelViewController: BaseViewController<Label> {
|
|||||||
.sink { [weak self] toggle in
|
.sink { [weak self] toggle in
|
||||||
NSMutableAttributedString.useMinimumLineHeight = toggle.isOn
|
NSMutableAttributedString.useMinimumLineHeight = toggle.isOn
|
||||||
self?.component.setNeedsUpdate()
|
self?.component.setNeedsUpdate()
|
||||||
|
self?.updateStyleLabel()
|
||||||
|
}.store(in: &subscribers)
|
||||||
|
|
||||||
|
useScaledLineHeight
|
||||||
|
.publisher(for: .valueChanged)
|
||||||
|
.sink { [weak self] toggle in
|
||||||
|
NSMutableAttributedString.useScaledLineHeight = toggle.isOn
|
||||||
|
self?.component.setNeedsUpdate()
|
||||||
|
self?.updateStyleLabel()
|
||||||
}.store(in: &subscribers)
|
}.store(in: &subscribers)
|
||||||
|
|
||||||
pointSizeRange.publisher(for: .valueChanged).sink(receiveValue: { [weak self] slider in
|
pointSizeRange.publisher(for: .valueChanged).sink(receiveValue: { [weak self] slider in
|
||||||
@ -215,7 +260,7 @@ class LabelViewController: BaseViewController<Label> {
|
|||||||
|
|
||||||
component.publisher(for: \.bounds)
|
component.publisher(for: \.bounds)
|
||||||
.sink { [weak self] rect in
|
.sink { [weak self] rect in
|
||||||
self?.calculatedLabel.text = "Actual height: \(rect.height)"
|
self?.calculatedLabel.text = "Actual height (* LineHeight x Text Lines): \(rect.height)"
|
||||||
}.store(in: &subscribers)
|
}.store(in: &subscribers)
|
||||||
|
|
||||||
//------------------------------------
|
//------------------------------------
|
||||||
@ -305,4 +350,3 @@ extension Slider {
|
|||||||
CGFloat((value * 100).rounded() / 100)
|
CGFloat((value * 100).rounded() / 100)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user